ぼるじょあがC/C++の宿題を片づけますYO! 48代目
■ このスレッドは過去ログ倉庫に格納されています
0476デフォルトの名無しさん
2005/07/26(火) 03:08:03エラーチェックとかほとんどしてないが。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int compare(const void *s1, const void *s2) {
return strcmp(*(char **)s1, *(char **)s2);
}
int main() {
char *lines[10], buf[100];
int i = 0, j;
FILE *fp = fopen("sort.txt", "r");
while (fgets(buf, 10, fp) != NULL) {
lines[i] = strdup(buf);
++ i;
}
fclose(fp);
qsort(lines, i, sizeof(char *), compare);
for (j = 0; j < i; j++) {
printf("%s", lines[j]);
}
}
■ このスレッドは過去ログ倉庫に格納されています