作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在代码中有这个函数,我试图输入 I/O 文件,但我似乎无法做到这一点。
void show_list(int whyeven[stuff], char *hatred[stuff])
{
for (int g = 0; g < stuff - 1; g++)
{
if (whyeven[g] < 10 || whyeven[g] == 0)
{
printf("%s - %d (*) you should buy more of this stuff\n\n",hatred[g], whyeven[g]);
}
else if (whyeven[g] > 10)
{
printf("%s - %d\n\n", hatred[g], whyeven[g]);
}
}
}
int main()
{
show_list(moarstuff, items);
return 0;
}
最佳答案
printf()
打印到 stdout
。您需要 fopen()
该文件,然后使用 fprintf()
以及从 fopen()
返回的 FILE*
指针作为第一个参数。
/* Open the file for writing */
FILE* fp = fopen("filename.txt", "w");
/* Check for errors */
if (fp == NULL)
{
/* Notify the user of the respective error and exit */
fprintf(stderr, "%s\n", strerror(errno));
exit(1);
}
/* Write to the file */
fprintf(fp, "Hello!\n");
/* Close the file */
fclose(fp);
注意:您的问题相当不清楚,这个答案是基于我所能理解的。
关于c - 如何在c中将函数输入到文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41226930/
我是一名优秀的程序员,十分优秀!