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;
}