Home › Forums › C Programming › Regarding replacing line of code?? › Reply To: Regarding replacing line of code??
April 28, 2008 at 10:14 am
#3385
Priyansh Agrawal
Participant
Sorry, your code looks very strange to me. Where do you want to place the output-file ? You opened an input-file for read-only. There you can’t make any changes.
Perhaps this should help you:
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 | <br /> #include <br /> <br /> int main(int argc,char **argv)<br /> {<br /> const int max=1024;<br /> int r=0,i;<br /> FILE *in,*out;<br /> char buff[max+3];<br /> <br /> if (argc!=3)<br /> {<br /> r=1;<br /> printf("usage: lower n");<br /> }<br /> else<br /> {<br /> if ((in=fopen(argv[1],"rb"))==NULL)<br /> {<br /> r=2;<br /> printf("cannot open input-file!n");<br /> }<br /> else<br /> {<br /> // Output file will be overwritten when exists !!!<br /> if ((out=fopen(argv[2],"wb"))==NULL)<br /> {<br /> r=3;<br /> printf("cannot open output-file!n");<br /> }<br /> else<br /> {<br /> while (!feof(in))<br /> {<br /> buff[0]=0;<br /> fgets(buff,max,in);<br /> <br /> for (i=0;i<max && buff!=0 && buff!='r' && buff!='n' && (buff==' ' || buff=='t');i++);<br /> <br /> if (buff=='#')<br /> {<br /> for (i=i+1;i<max && buff!=0 && buff!='r' && buff!='n';i++)<br /> {<br /> buff=tolower(buff);<br /> }<br /> }<br /> <br /> fputs(buff,out);<br /> }<br /> <br /> fclose(out);<br /> }<br /> <br /> fclose(in);<br /> }<br /> }<br /> <br /> return r;<br /> }<br /> |