c语言中fprintf函数
C中的fprintf()函数 (fprintf() function in C)
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等)。
C中的fprintf()示例 (fprintf() example in C)
#include
#include
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://bianchenghao.cn/hz/127177.html