Question
Write a c program.
CH-12 has arbitrary number of lines and one num. txt EXERCISE 12-11 te a program to create a new file numnew. txt that will h
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>

#include<stdlib.h>
int main(void) {
// creating a FILE variable
FILE *fptr;
FILE *wptr;
  
// integer variable
int numb,r,s=0;
char ch;
// open file for reading
fptr = fopen("D:/num.txt", "r");
//fail to open the file
if(fptr==NULL)
{
printf("\n Unable toopen the source file");
exit(0);
}


//open a file for writing
wptr = fopen("D:/numnew.txt", "w+");
//fail to open the file
if(fptr==NULL)
{
printf("\n Unable toopen the target file");
fclose(fptr);
exit(0);
}
//read data from num.txt
while (fscanf(fptr, "%d", &numb)!=EOF)
{
   
//reverse the number
s=0;
while(numb>0)
    {
       r=numb%10;
       s=s*10+r;
       numb=numb/10;
   }
  
//write the reverse number into file
fprintf(wptr, "%d\n", s);
}

  
// close connection
fclose(fptr);
fclose(wptr);
  
  
}

INPUT

num.txt

num Notepad File Edit Format View Help 352 569 845 2635 12 85 784 253 132 105

output file

numnew.txt

numnew Notepad File Edit Format View Help 253 965 548 5362 21 58 487 352 231 501

Add a comment
Know the answer?
Add Answer to:
Write a c program. CH-12 has arbitrary number of lines and one num. txt EXERCISE 12-11 te a program to create a new file numnew. txt that will he ine. A text file will have number in reverse order...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT