c语言中fprintf函数
Prototype:
原型:
int fprintf(FILE *filename, const char *string, . . . .);
Parameters:
参数:
FILE *filename, const char *string etc.
Return type: int
返回类型: int
Use of function:
使用功能:
Like printf() function, fprintf() function is used to write the argument statement string on the file stream. Through the fprintf() function we write or store the values with the string. The prototype of the function fprintf() is: int fprintf(FILE *filename, const char *string, . . . .);
与printf()函数类似, fprintf()函数用于在文件流上写入参数声明字符串。 通过fprintf()函数,我们可以将值写入或存储在字符串中。 函数fprintf()的原型是: int fprintf(FILE * filename,const char * string,。。。);
Here string is the user defined string along with the existing data types (likes int, float, char etc).
这里的string是用户定义的字符串以及现有的数据类型(例如int,float,char等)。
#include<stdio.h>
#include<stdlib.h>
int main()
{
//Initialize the file pointer
FILE *f;
char ch[100];
// open the file for read and write operation
if((f=fopen("includehelp.txt","r+"))==NULL){
//if the file does not exist print the string
printf("Cannot open the file...");
exit(1);
}
for(int i=0;i<10;i++){
//enter the strings with values in the file
fprintf(f,"The count number is %d\n",i+1);
}
fclose(f);
// open the file for read and write operation
if((f=fopen("includehelp.txt","r+"))==NULL){
//if the file does not exist print the string
printf("Cannot open the file...");
exit(1);
}
printf("File content is--\n");
printf("\n...............print the strings..............\n\n");
while(!feof(f)){
//takes the first 100 character in the character array
fgets(ch,100,f);
//and print the strings
printf("%s",ch);
}
//close the file
fclose(f);
return 0;
}
Output
输出量
翻译自: https://www.includehelp.com/c-programs/fprintf-function-in-c-language-with-example.aspx
c语言中fprintf函数
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/180603.html原文链接:https://javaforall.cn