C言語なら俺に聞け! Part 100
■ このスレッドは過去ログ倉庫に格納されています
0180デフォルトの名無しさん
05/01/24 14:59:01typedef struct tag_Station {
char name[256];
struct tag_Station *prev;
} Station;
int main(void) {
Station *currents = malloc(sizeof (Station));
Station *lasts = NULL;
if (currents == NULL)
return 1;
currents->prev = NULL;
puts("駅名入力(終了キー:/e)");
while (1) {
char buf[256];
fgets(buf, sizeof(buf), stdin);
buf[strlen(buf) - 1] = '\0';
if (strcmp(buf, "/e") == 0)
break;
strcpy(currents->name, buf);
lasts = malloc(sizeof (Station));
if (lasts == NULL)
break;
lasts->prev = currents;
currents = lasts;
}
while (currents->prev != NULL) {
puts(currents->name);
free(currents);
currents = currents->prev;
}
return 0;
}
■ このスレッドは過去ログ倉庫に格納されています