#include <stdio.h>
int main() {
char t;
while(1) {
t='\0';
printf("\nExit?(y/n): ");
scanf("%c", &t);
if(t=='y' || t=='Y') {
return 0;
}
else
printf("\nContinuing...");
}
return 0;
}
輸出:
$ vim Return.c
$ gcc -o Return Return.c
$ ./Return
Exit?(y/n): n
Continuing...
Exit?(y/n):
Continuing...
Exit?(y/n): n
Continuing...
Exit?(y/n):
Continuing...
Exit?(y/n): y
$
給'n'
作爲輸入之後,
Continuing...
Exit?(y/n):
循環一個更多時間,無需用戶輸入。如果代碼有任何錯誤,請告知我
後,你已經忘記了換行符'y' ... –