C PROGRAM TO REVERSE TEXT IN A FILE AND PRINTING THE TEXT:
1) Here, in the program first of all i created a file with some content.
2) I transfered the content into a string by size of the fell with using ftell() function.
3) I strated reversing the file and the stored in another file with the same size.
4) Now, transfer the content into the another file.
5) Print the string or you can print file.
INPUT:
file : input.txt
content : A computer is a machine which helps us to calculate, simulate and store different scenarios. For example, in order to write an e-mail, instead of paper and pen first we use a software (or program) called wordprocessor which helps us enter sentences through keyboard (Input), computer's screen (output) to read, and modem (output/input) to send it to a distant relative, friend, etc.
OUTPUT:
file : output.txt
content : .cte ,dneirf ,evitaler tnatsid a ot ti dnes ot )tupni/tuptuo( medom dna ,daer ot )tuptuo( neercs s'retupmoc ,)tupnI( draobyek hguorht secnetnes retne su spleh hcihw rossecorpdrow dellac )margorp ro( erawtfos a esu ew tsrif nep dna repap fo daetsni ,liam-e na etirw ot redro ni ,elpmaxe roF .soiranecs tnereffid erots dna etalumis ,etaluclac ot su spleh hcihw enihcam a si retupmoc A
Here is the program,
PROGRAM:
#include<stdio.h>
int main()
{
FILE *fp1,*fp2;
char ch;
int i=0,j=0,c=0,t;
fp1=fopen("input.txt","r");
fp2=fopen("output.txt","w");
fseek(fp1,0,2);
t=ftell(fp1);
fseek(fp1,0,0);
char s1[t],s2[t];
while((ch=fgetc(fp1))!=EOF)
{
s1[i]=ch;
i++;
}
s1[i]='\0';
for(i=0;s1[i]!='\0';i++);
for(i--;i>=0;i--)
{
s2[j]=s1[i];
j++;
}
s2[j]='\0';
fputs(s2,fp2);
printf("%s",s2);
fclose(fp1);
fclose(fp2);
return 0;
}
CLICK BELOW LINK FOR TO RUN CODE:
#CLICK HERE TO RUN THE PROGRAM
CLICK HERE FOR PREVIOUS PROGRAM
LEARN WITH JAGADEESH
copyright© to jagadeesh
Post a Comment