Home › Forums › C Programming › Beginner’s help › Reply To: Beginner’s help
March 24, 2008 at 4:39 pm
#3370
Participant
For the first part you could do:
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 | #include<br /> #include <br /> int main(void)<br /> {<br /> // open a text file for reading<br /> FILE * in_file;<br /> in_file = fopen("c:\programs\help\text1.txt","r");<br /> // open a text file for writing<br /> FILE * out_file ;<br /> out_file = fopen("c:\programs\help\text2.txt","w");<br /> <br /> if ( ! in_file || ! out_file )<br /> {<br /> printf ( "a file did not openn" );<br /> return 1;<br /> }<br /> char ch = fgetc ( in_file );<br /> while ( ch != EOF )<br /> {<br /> //write to file<br /> fputc ( ch , out_file );<br /> ch = fgetc ( in_file );<br /> }<br /> fclose(in_file);<br /> fclose(out_file);<br /> // system("pause");<br /> return 0;<br /> } |