程序忽略 for 循环体。迭代通过,但调试器不进入主体。 VS22 构建调试。
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
typedef struct List {
int data;
struct List* Next;
} List;
void Add(List* ls, int data) {
List* node = ls;
ls = malloc(sizeof(List));
ls->data = data;
ls->Next = node;
}
int main() {
List* ls = malloc(sizeof(List));
ls->Next = NULL;
ls->data = NULL;
if (ls->Next == NULL) {
ls->data = 2;
}
int i = 0;
while (1) {
char c = getchar();
char num[16];
if (isspace(c)) {
if (num[0] != '\0') {
Add(ls, atoi(num));
for (int j = 0; j <= i; j++) {
num[j] == '\0'; \\Полностью игнорируется
}
i=0;
}
continue;
}
else if (c == '.') {
if (num[0] != '\0') {
Add(ls, atoi(num));
i++;
for (; i <= 0; i--) {
num[i] == '\0';
}
}
break;
}
else if (isdigit(c)) {
num[i++] = c;
}
else {
printf("Error");
return 1;
}
}
while (ls->Next != NULL) {
printf("%d", ls->data);
}
return 0;
}