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();
}
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: