這是我收到的錯誤:試圖使用的atoi和它不工作
search.c: In function ‘checkGrades’:
search.c:63: warning: passing argument 1 of ‘atoi’ makes pointer from
integer without a cast
/usr/include/stdlib.h:148: note: expected ‘const char *’ but argument is
of type ‘char’
search.c:63: error: expected ‘)’ before ‘;’ token
這裏是我的代碼:如果
int checkGrades(STUDENT grades[], int maxrecs, FILE* fp)
{
char line[LINE_MAX];
int rc;
int count = 0;
int score;
char id;
while(fgets(line,LINE_MAX, fp) != NULL)
{
rc = sscanf(line,
"%25[^:]%*c%25[^:]%*c%6s%*c%3d%*c%3d%*c%3d%*c%3d%*c%3d%*c%2c",
grades[count].id,
&grades[count].score[1],
&grades[count].score[2],
&grades[count].score[3],
&grades[count].grade);
if((rc != 9) ||
rc == atoi (id);
grades[count].id < 100000 ||
grades[count].id > 999999 ||
grades[count].grade < 0 ||
grades[count].grade > 110)
{
printf("Invalid Record: %s", line);
}
else
{
count++;
if(count == TNARRAY_MAX)break;
}
printf("ID: ", grades-> id);
}
我不是很確定RC是林應該是用atoi,我是C的初學者,並且嘗試過很多連擊,但都沒有成功。我知道我需要在比較之前將字符串轉換爲int,但是在這裏我很迷茫,關於如何做到這一點。 任何幫助將不勝感激!
'atoi'的第一個參數應該是一個字符串,它是'char *'。 'id'是'char',而不是'char *'。 – Barmar
你也從未設置過'id'。 – Barmar
'if((rc!= 9)||''在'||'後面缺少另一個條件 – Barmar