我想通過在函數中使用scanf()
來獲取輸入字符串,但它保持失敗,我不知道爲什麼。掃描字符串輸入保持失敗
這是我的代碼的一部分。
typedef struct node {
int id;
char * name;
char * address;
char * group;
struct node * next;
} data;
void showG(data * head) {
char * n = "";
int i = 0;
data * current = head;
scanf("%s", n);
printf("The group of %s is\n", n);
while (current != NULL) {
if (0 == strcmp(current->group, n)) {
printf("%d,%s,%s\n", current->id, current->name, current->address);
i = 1;
}
current = current->next;
}
if (0 == i) {
printf("no group found");
}
}
對不起,如果我將n更改爲「1」並刪除scanf的句子,另一部分將工作,這意味着它將printf「1的組是......」的東西,但如果我保持scanf並運行程序,它會停止,當我想輸入更改n的值 – YoarkYANG