【发布时间】:2016-05-11 05:21:31
【问题描述】:
谁能帮我写代码
void gotoxy(int, int);
void clrscr();
void dispMenu();
int main(void){
int choice;
choice = 0;
menu:
dispMenu();
scanf("%d", &choice);
if(choice==1){
clrscr();
char name[100];
printf("Please Input your Complete name: ");
scanf("%[^\n]s", &name);
printf("Your name is: %s \n", name);
}
getch();
goto menu;
}
void dispMenu(){
gotoxy(23,9);
printf("List of C-Lang Activities\n");
gotoxy(23,11);
printf("1. Input Name");
gotoxy(23,12);
printf("2. (blank) \n");
gotoxy(23,13);
printf("3. (blank) \n");
gotoxy(23,14);
printf("4. (blank)\n");
gotoxy(23,15);
printf("5. (blank)\n");
gotoxy(23,17);
printf("Please Enter the Number of your choice: ");
}
void gotoxy(int x, int y){
HANDLE hConsoleOutput;
COORD dxCursorPosition;
dxCursorPosition.X = x;
dxCursorPosition.Y = y;
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hConsoleOutput, dxCursorPosition);
}
void clrscr(){
system("cls");
}
当我尝试将程序放入表格菜单时遇到问题:
输出会是这样的
Please Input your Complete Name: John Kenneth
Your Name is: John Kenneth
【问题讨论】:
-
scanf("%[^\n]s", &name);不要在这里使用&并且%[本身就是一个说明符,所以不要在它后面加上s。
标签: c removing-whitespace