ここで何が起こっているのかよくわかりません.Imがただのばかなのか、コンパイラの何かがおかしいのか.
以下のコードは、私の searchList 関数を呼び出した後、ユーザーからの入力を取得する必要がありますが、代わりに、プログラムは単に終了し、セグ フォールトさえ発生せず、文字通りただ終了します。ばかげたこと?
編集: searchNode は searchList です。タイプミスで申し訳ありません。
乾杯。
typedef struct List {
char c;
struct List *next;
}List;
List* insertNode(char c, List* t1);
List* addNode(void);
List* searchList(List *t1);
int main(void) {
List *z = addNode();
List *search_result;
char s;
while ( z != NULL) {
printf("%c", z->c);
z = z->next;
}
search_result = searchList(z);
return 0;
}
List *addNode(void) {
List *head = (List*)calloc(1,sizeof(List));
char c;
while (( c = getchar()) != '.') {
head = insertNode(c, head);
}
return head;
}
List *insertNode(char c, List* t1) {
List *tail = (List*)calloc(1,sizeof(List));
tail->c = c;
tail->next = t1;
return tail;
}
List *searchList(List *t1) {
char c;
printf("Please enter a search term");
scanf("%c", &c);
while (t1 != NULL) {
if (t1->c == c) {
return t1;
}
t1 = t1->next;
}
return 0;
}