幾天前我開始學習C語言,現在已經介紹了我正在嘗試製作一個基於文本的小遊戲的基礎知識。爲什麼這給了我一個邏輯錯誤?
只是讓這個菜單功能我試圖運行我的應用程序,由於某種原因它不工作後:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int menu() {
char *start;
printf("Welcome to my game\n Type START to begin or EXIT to quit: ");
while (strcmp(start, "start") != 0 && strcmp(start, "exit") != 0) {
scanf("%s", &start);
if (strcmp(start, "start") == 0) {
return 1;
} else
if (strcmp(start, "exit") == 0) {
return 0;
} else {
printf("Invalid command. Try again: ");
}
}
}
請不要太技術與你的答案,因爲我還是很陌生以C和編程本身。
您能更具體地瞭解您的預期功能與實際發生的情況嗎? –
親愛的喬治,「*它不起作用*」是或多或少值得提供的錯誤描述。請更具體地說明什麼是不行的,你得到了什麼,你會期望得到什麼。 – alk
請學習使用調試器 – Minh