C/C++の宿題を片付けます 93代目at TECH
C/C++の宿題を片付けます 93代目 - 暇つぶし2ch146:デフォルトの名無しさん
07/07/17 09:22:08
>>112
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct{
    char num[128], name[128], adr[128], tel[128];
}Data;

int main(int argc, char *argv[])
{
    Data x[10];
    FILE *fp;
    int i = 0, j;
    char buf[1024], *p, search[128];
    if(argc < 2) fprintf(stderr, "usage : %s string\n", argv[0]), exit(1);
    if((fp = fopen(argv[1], "r")) == NULL) perror(argv[1]), exit(2);
    while(fgets(buf, sizeof(buf), fp) != NULL){
        printf("num : "), scanf("%s", x[i].num);
        if((p = strtok(buf, ",")) != NULL) sscanf(p, "%s", x[i].name);
        if((p = strtok(NULL, ",")) != NULL) sscanf(p, "%s", x[i].adr);
        if((p = strtok(NULL, ",")) != NULL) sscanf(p, "%s", x[i].tel);
        i++;
    }
    for(j = 0; j < i; j++)
        printf("%s %s\n", x[j].num, x[j].name);
    printf("search : "), scanf("%s", search);
    for(j = 0; j < i; j++)
        if(!strcmp(search, x[j].num))
            printf("%s %s %s\n", x[j].name, x[j].adr, x[j].tel);
    return 0;
}


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch