如何使scanf工作? [英] How do I make the scanf to work ?

查看:136
本文介绍了如何使scanf工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//这只是大代码的一部分。在此功能中,我希望打印链接列表中的所有结果,其具有与用户输入的相同的邮政编码。但是从用户输入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)阅读文档: http://www.cplusplus.com/reference / cstdio / scanf [ ^ ]。< br $>


-SA

For further progress, 1) use the debugger, 2) read the documentation: http://www.cplusplus.com/reference/cstdio/scanf[^].

—SA


这篇关于如何使scanf工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆