C/C++の宿題を片付けます 96代目
at TECH
498:デフォルトの名無しさん
07/09/29 19:23:14
>>495
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]){
FILE *fp;
int row = 0, col = 0, max_col = 0, i, j;
char buf[128], *p, str[128][128][3] = {0};
if(argc < 2 || (fp = fopen(argv[1], "r")) == NULL) return 0;
while(fgets(buf, sizeof(buf), fp) != NULL){
p = strtok(buf, " \n");
while((p = strtok(NULL, " \n")) != NULL) strcpy(str[row][col++], p);
row++, col = 0;
}
fclose(fp);
for(i = 0; i < row; i++){
for(j = 0; str[i][j][0] != '\0'; j++) ;
if(j > max_col) max_col = j;
}
for(j = 0; j < max_col; j++){
for(i = 0; i < row; i++)
if(str[i][j][0] != '\0') printf("%2s ", str[i][j]);
else printf("%*c", 3, 32);
printf("\n");
}
return 0;
}
次ページ続きを表示1を表示最新レス表示スレッドの検索類似スレ一覧話題のニュースおまかせリスト▼オプションを表示暇つぶし2ch
5282日前に更新/230 KB
担当:undef