#include <stdio.h>
int main(void)
{
FILE *fp;
char ch;
fp = fopen("sample", "r+");
if(fp == NULL)
{
printf("\nUnable to open file for reading and writing");
return 1;
}
ch = fgetc(fp);
printf("\n%c", ch);
/* Seek fifth character from the end of file */
fseek(fp, -5, SEEK_END);
ch = fgetc(fp);
printf("\n\t%c", ch);
/* Seek tenth character from the beginning of file */
fseek(fp, 10, SEEK_SET);
ch = fgetc(fp);
printf("\n\t%c", ch);
/* Seek next character from the current position */
fseek(fp, 1, SEEK_CUR);
ch = fgetc(fp);
printf("\n\t%c", ch);
/* Reset file pointer to the beginning of the file */
fseek(fp, 0, SEEK_SET);
fputc('#', fp);
fclose(fp);
return 0;
}
int main(void)
{
FILE *fp;
char ch;
fp = fopen("sample", "r+");
if(fp == NULL)
{
printf("\nUnable to open file for reading and writing");
return 1;
}
ch = fgetc(fp);
printf("\n%c", ch);
/* Seek fifth character from the end of file */
fseek(fp, -5, SEEK_END);
ch = fgetc(fp);
printf("\n\t%c", ch);
/* Seek tenth character from the beginning of file */
fseek(fp, 10, SEEK_SET);
ch = fgetc(fp);
printf("\n\t%c", ch);
/* Seek next character from the current position */
fseek(fp, 1, SEEK_CUR);
ch = fgetc(fp);
printf("\n\t%c", ch);
/* Reset file pointer to the beginning of the file */
fseek(fp, 0, SEEK_SET);
fputc('#', fp);
fclose(fp);
return 0;
}
No comments:
Post a Comment
kiss on google ads if you are anonymous because your ip is trackable.thank you.
......from.admin