//这只是大代码的一部分。在此功能中,我希望打印链接列表中的所有结果,其具有与用户输入的相同的邮政编码。但是从用户输入zipcode的scanf似乎不起作用。当我打印邮政编码时,它表示NULL //
//This is just a part of a big code. In this function I want ot print all the results in the linked list having the same zipcode as the one entered by the user. But the scanf to input the zipcode from the user doesn''t seem to work. When i print the zipcode it says NULL//
void searchzip() { char code[6]; printf("\nPlease enter the zip code that you want to search :\n"); scanf("%s",code[6]); printf("\n%s",code[6]); struct student *temp=head; do { if(strcmp(code,temp->zip)==0) { printf("\nFirst name: %s Last name: %s Score: %f ZipCode: %s",temp->firstname,temp->lastname,temp->score,temp->zip); } temp=temp->next; } while(temp!=NULL); }推荐答案
首先, First of all, scanf("%s",code);
但是,不清楚为什么要将它扫描为字符串(%s),为什么不使用 gets_s 。如果你想要邮政编码,可以是
But then, it''s not clear why scanning it as string ("%s"), why not using gets_s. If you want zip code, it could be
int zipCode; scanf("%d", &zipCode);有关进一步的进展,1)使用调试器,2)阅读文档: www.cplusplus/reference / cstdio / scanf [ ^ ]。
For further progress, 1) use the debugger, 2) read the documentation: www.cplusplus/reference/cstdio/scanf[^].
更多推荐
如何使scanf工作?
发布评论