我目前正在处理文件 I/O,并尝试使用此功能:
fprintf (FILE *pFile, char *pFormat, <variable list>);
用我的变量
fprintf ( filePtr, "\"%s\"n", myarray );
我的编译器发出警告,warning: format '%s' expects a matching 'char *' argument
但我已声明myarray
为char *myarray = "This is a string"
. 谁能告诉我出了什么问题?我的代码是:
#include <stdio.h>
int main ()
{
FILE *filePtr;
char *myarray = "This is a string";
if ((filePtr = fopen("sample.dat", "w")) == NULL) {
printf ("File could not be opened.\n");
} else {
printf ("This will print the string onto file:\n");
while (!feof(filePtr)) {
fprintf ( filePtr, "\"%s\"", myarray );
}
}
fclose (filePtr);
return 0;
}