我正在使用Xcode 8學習C,編譯器在執行while或for循環後不運行任何代碼。這是一個錯誤?我該如何解決它?執行while或for循環後沒有代碼執行C
在下面printf("code executed after while-loop");
提供的例子中從未執行
#include <stdio.h>
int getTheLine(char string[]);
int getTheLine(char string[]) {
char character;
int index;
index = 0;
while ((character = getchar()) >= EOF) {
string[index] = character;
++index;
}
printf("code executed after while-loop");
return index;
}
int main(int argc, const char * argv[]) {
char string[100];
int length = getTheLine(string);
printf("length %d\n", length);
return 0;
}
您可以開始向我們展示您的代碼。 –
編譯器不應該運行任何代碼。它應該將[*翻譯單元*](https://en.wikipedia.org/wiki/Translation_unit_(programming))編譯成目標文件,然後將其鏈接到可執行文件中。 IDE然後可以啓動一個進程來運行可執行文件。 –
更重要的是,請[閱讀關於如何提出好問題](http://stackoverflow.com/help/how-to-ask)並學習如何創建[最小,完整和可驗證示例](http ://stackoverflow.com/help/mcve)。 –