如何使scanf工作?

编程入门 行业动态 更新时间:2024-10-20 07:49:18
本文介绍了如何使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)阅读文档: www.cplusplus/reference / cstdio / scanf [ ^ ]。

-SA

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

—SA

更多推荐

如何使scanf工作?

本文发布于:2023-11-25 15:27:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630298.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:工作   scanf

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!