C program read input file and output with "\n" new line every 50 characters -


void filecopy(file *ifp, file *ofp) {   int c;    while((c = getc(ifp))!= eof)     putc(c,ofp); } 

so, have try:

void filecopy(file *ifp, file *ofp) {   int c;   int count = 0;    while((c = getc(ifp))!= eof)     if(count == 50){      putc("\n",ofp);//this didnt work      count = 0;      }     putc(c,ofp); } 

am supposed use type of pointers? im not c pointers, know? thank you.

your putc attempting output string, pointer. putc takes initial 8 bits char of variable, not \n in case.

you want (note single quotes):

putc('\n', ofp); 

if using windows, may need output \r\n desired result.

finally, loop isn't testing every 50 characters, it's outputting value on each loop iteration. assume have done test.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -