Scanf with spaces does not read at all

#include int main(){ int i; char name[10],surname[10],id[12],dpart[20]; printf("******** ID Documentation ***********\n\n\n"); printf("1) What is your Name? \n"); scanf("%s",&name); printf("2) What is your Surname? \n"); scanf("%s",&surname); printf("3) What is your ID Number \n"); scanf("%s",&id); printf("4) What is your Department? \n"); scanf("%[^\n]",&dpart); system("CLS"); for(i=0;i<50;i++){printf("*");}printf("\n"); printf("|"); for(i=0;i<48;i++){printf("%%");} printf("|");printf("\n");printf("|"); for(i=0;i<14;i++){printf("%%");} printf(" STUDENT ID CARD ");for(i=0;i<17;i++){printf("%%");}printf("|\n");printf("|"); for(i=0;i<48;i++){printf("%%");} printf("|\n"); printf(" //////// NAME: %6s ",name);for(i=0;i<26;i++){printf("/");}printf(" \n|");for(i=0;i<48;i++){printf("-");}printf("|\n"); printf(" //////// SURNAME: %6s ",surname);for(i=0;i<23;i++){printf("/");}printf(" \n|");for(i=0;i<48;i++){printf("-");}printf("|\n"); printf(" //////// ID NUMVER: %11s ",id);for(i=0;i<16;i++){printf("/");}printf(" \n|");for(i=0;i<48;i++){printf("-");}printf("|\n"); printf(" //////// DEPARTMENT: %22s ",dpart);for(i=0;i<4;i++){printf("/");}printf(" \n|");for(i=0;i<48;i++){printf("-");}printf("|\n"); printf("|"); for(i=0;i<48;i++){printf("%%");} printf("|");printf("\n"); printf("|"); for(i=0;i<48;i++){printf("%%");} printf("|");printf("\n"); printf("|"); for(i=0;i<48;i++){printf("%%");} printf("|");printf("\n");for(i=0;i<50;i++){printf("*");} } I was helping one of my friends on his homework. We have to read the department data than display it on a id card, but when it comes to reading department, the program skips it and adds the value entered for id number to department. Ps: I know that using scanf() is a very bad work, but they didn't learned anything else so i cannot suggest using sscanf to him And also don't care the messy code when writing out data, it works
bad idea ... and also don't care the messy code when showing it to people who might help you ...

以上就是Scanf with spaces does not read at all的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » CSS3 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏