Home › Forums › C Programming › Read 1st col vals of i/pfile;create o/p fl for each diff val › Re: Re: Read 1st col vals of i/pfile;create o/p fl for each diff val
August 21, 2009 at 3:58 pm
#3606
GWILouisaxwzkla
Participant
Heres some code that does what you want ( maybe you can splice this into your program ):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | <br /> <br /> /****************************************************************<br /> * File Name : c:programstempCG.cpp<br /> * Date : August,10,2009<br /> * Comments : new project<br /> * Compiler/Assembler : Visual C++ 6.0<br /> * Modifications :<br /> *<br /> *<br /> *<br /> *<br /> *<br /> * Program Shell Generated At: 3:17:50 p.m.<br /> =-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /> <br /> <br /> <br /> #include < stdio.h ><br /> //#include < conio.h ><br /> //#include < math.h ><br /> //#include < iomanip ><br /> //#include < ctype.h ><br /> <br /> //using namespace std;<br /> <br /> //main function ******************************<br /> <br /> int main ( )<br /> {<br /> <br /> //CHANGE FILE NAMES TO WHAT YOU WANT HERE !!!!!!!!!!!!!!!!!!!!!<br /> <br /> FILE * inputFile = fopen ( "c:\programs\data.txt", "r+" );<br /> <br /> FILE * outputFile;<br /> <br /> <br /> //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@<br /> <br /> char ch;<br /> char newline = 10;<br /> int commaCount;<br /> <br /> <br /> char fileName [ 50 ] ;<br /> strcpy ( fileName , "c:\programs\" );<br /> <br /> <br /> fileName [ 12 ] = fgetc ( inputFile );<br /> fileName [ 13 ] = fgetc ( inputFile );<br /> fileName [ 14 ] = '.';<br /> fileName [ 15 ] = 't';<br /> fileName [ 16 ] = 'x';<br /> fileName [ 17 ] = 't';<br /> fileName [ 18 ] = 0;<br /> fgetc ( inputFile );<br /> while ( ! feof ( inputFile ) )<br /> {<br /> <br /> <br /> <br /> ch = fgetc ( inputFile );<br /> outputFile = fopen ( fileName , "a" );<br /> commaCount = 0;<br /> while ( ch != newline && commaCount < 4)<br /> {<br /> if ( ch == ',' )<br /> commaCount ++;<br /> else<br /> fputc ( ch , outputFile );<br /> ch = fgetc ( inputFile );<br /> }<br /> fputc ( ' ' , outputFile );<br /> //flush rest of line<br /> while ( ch != newline )<br /> ch = fgetc ( inputFile );<br /> fclose ( outputFile );<br /> <br /> <br /> <br /> fileName [ 12 ] = fgetc ( inputFile );<br /> fileName [ 13 ] = fgetc ( inputFile );<br /> fileName [ 14 ] = '.';<br /> fileName [ 15 ] = 't';<br /> fileName [ 16 ] = 'x';<br /> fileName [ 17 ] = 't';<br /> fileName [ 18 ] = 0;<br /> fgetc ( inputFile );<br /> }<br /> <br /> <br /> return 0 ;<br /> }<br /> <br /> <br /> <br /> |