C语言中的fprintf()

fprintf用于打印文件中的内容,而不是标准输出控制台。

null
int fprintf(FILE *fptr, const char *str, ...);

例子:

C

// C Program for the above approach
#include<stdio.h>
int main()
{
int i, n=2;
char str[50];
//open file sample.txt in write mode
FILE *fptr = fopen ( "sample.txt" , "w" );
if (fptr == NULL)
{
printf ( "Could not open file" );
return 0;
}
for (i = 0; i < n; i++)
{
puts ( "Enter a name" );
scanf ( "%[^]%*c" , str);
fprintf (fptr, "%d.%s" , i, str);
}
fclose (fptr);
return 0;
}


Input: GeeksforGeeks       GeeksQuizOutput:  sample.txt file now having output as 0. GeeksforGeeks1. GeeksQuiz

如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。

© 版权声明
THE END
喜欢就支持一下吧
点赞8 分享