Write a C program to reverse the first n characters in a file, where n is given by the user.
Program Code:
#include <stdio.h>
#include<string.h>
int main()
{
FILE *fp;
char a[50];
int i,n,count=0;
fp=fopen("program.txt","r");
if(fp==NULL)
{
printf("\n file opening problem");
return;
}
printf("\n enter the no of charcters to reverse: ");
scanf("%d",&n);
while(count<n)
{
a[count]=fgetc(fp);
count++;
}
a[count]='\0';
fputs(strrev(a),stdout);
fclose(fp);
getch();
}
Post A Comment:
0 comments: