Professional Documents
Culture Documents
Ans1.)#include <stdio.h>
int main(){
FILE *fptr;
char sentence[30];
fptr=fopen("sent.txt","w");
fprintf(fptr,"This is the content of the test file");
printf("Input a sentence for the file:");
gets(sentence);
fclose(fptr);
printf("\nThe content of test file is created successfully...!!");
}
Ans4.) #include<stdio.h>
int main(){
FILE *fptr;
int num=0;
char fname[40],str;
printf("Enter file name:");
scanf("%s",fname);
fptr=fopen(fname,"r");
str=getc(fptr); while(str!
=EOF){
if(str=='\0');
{ num++;
}
str=getc(fptr);
}
fclose(fptr);
printf("There are %d lines in %s",num,fname);
return 0;
}