C program using functions – fgetc(), fgets(), fputs(), fputc()

C program using functions – fgetc(), fgets(), fputs(), fputc() - Blurnooz.com

Collection of C programm using functions. Get C program with output of using functions like fgetc(), fgets(), fputs(), and fputc().C program output with download link below end of program.

Write a program to illustrate reading file contents.

PROGRAM :-

#include.........
#include.........
void main()
{
charch,f_name[25];
FILE *fp;
clrscr();
printf("Enter the name of the file u want to open:");
gets(f_name);
fp=fopen(f_name,"r");
if(fp==NULL)
{
	printf("Error");
	exit(1);
}
while((ch=fgetc(fp))!=EOF)
{
	printf("%c",ch);
}
fclose(fp);
getch();
}

Output :-

C program using functions - read(), fgets(), fputs(), fputc() - Blurnooz C program using functions - read(), fgets(), fputs(), fputc() - Blurnooz

 

Write a program to illustrate the use of fgets().

#include........
#include........
void main()
{
    FILE *fp;
    char buffer[250],f_name[25];
    clrscr();
    printf("Enter the name of the file u want to open:");
    gets(f_name);
    fp=fopen(f_name,"r");
    fgets(buffer,25,fp);
    puts(buffer);
    getch();
}

Output :-C program using functions – fgetc(), fgets(), fputs(), fputc() - Blurnooz

 

Write a program to illustrate the use of fputs().

#include.........
#include.........
void main()
{
FILE *fp;
char text[100];
clrscr();
printf("Enter a text:");
gets(text);
if((fp=fopen("n.txt","w"))==NULL)
{
	printf("Can not open file");
	exit(1);
}
fputs(text,fp);
fclose(fp);
getch();
}

Output :-

C program using functions – fgetc(), fgets(), fputs(), fputc() - Blurnooz

C program using functions – fgetc(), fgets(), fputs(), fputc() - Blurnooz

Write a program to illustrate the use of fputc().

#include.........
#include.........
void main()
{
FILE *fp;
char c;
clrscr();
printf("Enter a character:");
c=getchar();
if((fp=fopen("n1.txt","w"))==NULL)
{
	printf("Can not open file");
	exit(1);
}
fputc(c,fp);
fclose(fp);
getch();
}

Output :-

C program using functions – fgetc(), fgets(), fputs(), fputc() - Blurnooz

Leave a Reply

Please enter your comment!
Please enter your name here

*