csv形式でファイルから読み込んだものを重連結リストに格納する

c

1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4 5typedef struct __Soccercheck // 構造体6{7 int Ranking; // ランキング8 char Name[256]; // 選手の名前9 char Team[256]; // チーム名10 int Age; // 年齢11 char Country[256]; // 国籍12 int Number; // ゴール数13 int Games; // 出場試合数14 struct __Soccercheck *next;15 struct __Soccercheck *prev;16} Soccercheck;17 18Soccercheck *append(Soccercheck *tail, int rank, const char *name, const char *team, int age, const char *cou, int num, int game) // データを格納する関数19{20 Soccercheck *x = malloc(sizeof(Soccercheck));21 x->Ranking = rank;22 strcpy(x->Name, name);23 strcpy(x->Team, team);24 x->Age = age;25 strcpy(x->Country, cou);26 x->Number = num;27 x->Games = game;28 29 x->next = tail->next;30 x->prev = tail;31 tail->next->prev = x;32 tail->next = x;33 tail = tail->next;34 35 return tail;36}37void dis(Soccercheck *tmp){38printf("サッカープレミアリーグ得点ランキング %2d 選手名 %s チーム名 %s 年齢 %d 国籍 %s ゴール数 %2d 出場試合数 %d\n", tmp->Ranking, tmp->Name, tmp->Team, tmp->Age, tmp->Country, tmp->Number, tmp->Games);39printf("発見したデータに対応する構造体のアドレスは以下の通り。\n"); // アドレスの表示40printf("Ranking: %p\n", &tmp->Ranking);41printf("Name: %p\n", &tmp->Name);42printf("Team: %p\n", &tmp->Team);43printf("Age: %p\n", &tmp->Age);44printf("Country: %p\n", &tmp->Country);45printf("Number: %p\n", &tmp->Number);46printf("Games: %p\n", &tmp->Games);47}48int main(void)49{50 Soccercheck *dommy = (Soccercheck *)malloc(sizeof(Soccercheck)); // ダミーノード51 Soccercheck *head = dommy;52 Soccercheck *tail = dommy;53 dommy->next = dommy;54 dommy->prev = dommy;55 56 tail = append(tail, 1, "ハーランド", "マンチェスターC", 22, "ノルウェー", 36, 33);57 tail = append(tail, 2, "ケーン", "トットナム", 29, "イングランド", 27, 36);58 tail = append(tail, 3, "トニー", "ブレントフォード", 27, "イングランド", 20, 33);59 tail = append(tail, 4, "サラー", "リバプール", 30, "エジプト", 19, 36);60 tail = append(tail, 5, "C・ウィルソン", "ニューカッスル", 31, "イングランド", 18, 29);61 tail = append(tail, 6, "ラッシュフォード", "マンチェスターU", 25, "イングランド", 16, 33);62 tail = append(tail, 7, "ウーデゴール", "アーセナル", 24, "ノルウェー", 15, 35);63 tail = append(tail, 7, "マルティネリ", "アーセナル", 21, "ブラジル", 15, 36);64 tail = append(tail, 9, "ワトキンス", "アストンビラ", 27, "イングランド", 14, 35);65 tail = append(tail, 10, "サカ", "アーセナル", 21, "イングランド", 13, 36);66 tail = append(tail, 11, "ロドリゴ", "リーズ", 32, "スペイン", 12, 29);67 tail = append(tail, 11, "バーンズ", "レスター", 25, "イングランド", 12, 32);68 tail = append(tail, 11, "ミトロビッチ", "フラム", 28, "セルビア", 12, 22);69 tail = append(tail, 14, "アルミロン", "ニューカッスル", 29, "パラグアイ", 11, 32);70 tail = append(tail, 15, "ガブリエル・ジェズス", "アーセナル", 26, "ブラジル", 10, 24);71 tail = append(tail, 15, "イサク", "ニューカッスル", 23, "スウェーデン", 10, 20);72 tail = append(tail, 15, "ソン・フンミン", "トットナム", 30, "韓国", 10, 34);73 tail = append(tail, 15, "フォーデン", "マンチェスターC", 22, "イングランド", 10, 29);74 tail = append(tail, 15, "マディソン", "レスター", 26, "イングランド", 10, 28);75 tail = append(tail, 15, "マック・アリスター", "ブライトン", 24, "アルゼンチン", 10, 32);76 tail = append(tail, 15, "エゼ", "クリスタルパレス", 24, "イングランド", 10, 36);77 tail = append(tail, 22, "フィルミノ", "リバプール", 31, "ブラジル", 9, 23);78 tail = append(tail, 22, "ヌニェス", "リバプール", 23, "ウルグアイ", 9, 29);79 tail = append(tail, 24, "トロサール", "アーセナル", 28, "ベルギー", 8, 34);80 tail = append(tail, 24, "アウォニイ", "ノッティンガム・フォレスト", 25, "ナイジェリア", 8, 25);81 tail = append(tail, 24, "ジョンソン", "ノッティンガム・フォレスト", 21, "ウェールズ", 8, 36);82 tail = append(tail, 24, "イングス", "ウエストハム", 30, "イングランド", 8, 33);83 tail = append(tail, 24, "アルバレス", "マンチェスターC", 23, "アルゼンチン", 8, 28);84 tail = append(tail, 24, "ギュンドアン", "マンチェスターC", 32, "ドイツ", 8, 30);85 tail = append(tail, 24, "ウォード・プラウズ", "サウサンプトン", 28, "イングランド", 8, 36);86 tail = append(tail, 24, "グロス", "ブライトン", 31, "ドイツ", 8, 34);87 tail = append(tail, 32, "三笘", "ブライトン", 25, "日本", 7, 30);88 89 90 return 0;91}92

コメントを投稿

0 コメント