C/C++の宿題を片付けます 96代目at TECH
C/C++の宿題を片付けます 96代目 - 暇つぶし2ch498:デフォルトの名無しさん
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