scanf的问题
代码
while(1) { printf("Your choose:"); fflush(stdin); if(scanf("%d", &choice) != 1) choice = 5; printf("%d\n", choice); memcpy(buf, &choice, sizeof(choice)); if((sendBytes = send(sockfd, buf, sizeof(choice), 0)) == -1) { perror("send choice"); } switch(choice) { case 1:recvdirlist(sockfd);break; case 2:recvfile(sockfd, 0);break; case 3:recvdir(sockfd, 0);break; case 4:cliexit(sockfd);break; default:printf("Please a number from 1-4 to represent your choice\n"); } }Breakpoint 1, main (argc=2, argv=0xbffff2f4) at ftpcli.c:8181 if(scanf("%d", &choice) != 1)(gdb) cContinuing.Your choose:a5Please a number from 1-4 to represent your choiceBreakpoint 1, main (argc=2, argv=0xbffff2f4) at ftpcli.c:8181 if(scanf("%d", &choice) != 1)(gdb) s82 choice = 5;(gdb) s83 printf("%d\n", choice);(gdb)