我正在尝试将前 N 个素数的数组写入 txt 文件,每行有 5 个条目,每个条目之间有 10 个空格。相关代码如下:
#include<stdio.h>
#include<math.h>
#define N 1000
...
void writePrimesToFile(int p[N], char filename[80])
{
int i;
FILE *fp = fopen(filename, "w");
for(i = 0; i<=N-1; i++)
{
for(i = 0; i<5; i++)
{
fprintf(filename, "%10%i", p[i]);
}
printf("/n");
fclose(fp);
}
printf("Writing array of primes to file.\n");
}
编译器抛出以下错误:
primes.c:40:4: warning: passing argument 1 of ‘fprintf’ from incompatible pointer type [enabled by default]
fprintf(filename, "%10%i", p[i]);
^
In file included from /usr/include/stdio.h:29:0,
from primes.c:1:
/usr/include/stdio.h:169:5: note: expected ‘struct FILE *’ but argument is of type ‘char *’
int _EXFUN(fprintf, (FILE *, const char *, ...)
^
许多谷歌搜索都没有结果。任何帮助将非常感激。