Home › Forums › C Programming › Reading first column in a file and creating new files… › Re: Re: Reading first column in a file and creating new files…
August 11, 2009 at 6:00 pm
#3601
GWILouisaxwzkla
Participant
This seems to work:
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 99 100 101 102 103 104 105 | <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 /> #include <br /> #include <br /> //#include <br /> //#include <br /> //#include <br /> //#include <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 * outputFile1 = fopen ( "c:\programs\data2.txt", "w+" );<br /> FILE * outputFile2 = fopen ( "c:\programs\data3.txt", "w+" );<br /> FILE * outputFile3 = fopen ( "c:\programs\data4.txt", "w+" );<br /> FILE * outputFile4 = fopen ( "c:\programs\data5.txt", "w+" );<br /> <br /> //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@<br /> <br /> char ch;<br /> char newline = 10;<br /> <br /> ch = fgetc ( inputFile );<br /> fgetc ( inputFile );<br /> while ( ! feof ( inputFile ) )<br /> {<br /> <br /> if ( ch == 'A' )<br /> {<br /> ch = fgetc ( inputFile );<br /> while ( ch != newline )<br /> {<br /> fputc ( ch , outputFile1 );<br /> ch = fgetc ( inputFile );<br /> }<br /> fputc ( 'n' , outputFile1);<br /> }<br /> if ( ch == 'B' )<br /> {<br /> ch = fgetc ( inputFile );<br /> while ( ch != newline )<br /> {<br /> fputc ( ch , outputFile2 );<br /> ch = fgetc ( inputFile );<br /> }<br /> fputc ( 'n' , outputFile2 );<br /> }<br /> if ( ch == 'C' )<br /> {<br /> ch = fgetc ( inputFile );<br /> while ( ch != newline )<br /> {<br /> fputc ( ch , outputFile3 );<br /> ch = fgetc ( inputFile );<br /> }<br /> fputc ( 'n' , outputFile3);<br /> }<br /> if ( ch == 'D' )<br /> {<br /> ch = fgetc ( inputFile );<br /> while ( ch != newline )<br /> {<br /> fputc ( ch , outputFile4 );<br /> ch = fgetc ( inputFile );<br /> }<br /> fputc ( 'n' , outputFile4);<br /> }<br /> <br /> ch = fgetc ( inputFile );<br /> fgetc ( inputFile );<br /> }<br /> fclose ( outputFile1 );<br /> fclose ( outputFile2 );<br /> fclose ( outputFile3 );<br /> fclose ( outputFile4 );<br /> <br /> return 0 ;<br /> }<br /> <br /> <br /> <br /> <br /> |