我想知道如何使用文件中的标记化行设置结构的字符串值。基本上我正在读一行"Person 100 100"
(由 分隔\t
),我需要用返回的内容设置结构的字符串值。
错误信息:
||In function 'main':|
|32|warning: passing argument 1 of 'strcpy' from incompatible pointer type|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\string.h|45|note: expected 'char *' but argument is of type 'char **'|
||=== Build finished: 0 errors, 1 warnings ===|
代码片段:
char buffer[20];
fgets(buffer, 20, file);
while (*buffer != EOF)
{
struct student temp;
char *result = NULL;
//set name
strcpy(temp.name,strtok(buffer,"\t"));
//set midterm
result = strtok(NULL, "\t");
temp.midterm = atoi(result);
//set final
result = strtok(NULL, "\t");
temp.final = atoi(result);
}