teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

削除済みの投稿

2020/07/08 06:45

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,48 +1,1 @@
1
- strcpyについての質問です。しばらくはこのコードでちょくちょくわからないことがあったら、質問するのでお願いします。
2
-
3
- ```#define _CRT_SECURE_NO_WARNINGS
4
- #define HASHSIZE 17
5
- #include <stdio.h>
6
- #include <stdlib.h>
7
- #include<string.h>
8
-
9
- struct match* hashtable[HASHSIZE];
10
-
11
- struct match {
12
- char *home;
13
- char *away;
14
- struct match_score* r;
15
- struct match *next;
16
- };
17
-
18
-
19
- void add(int year, int month, int day, char* home_team, int home_score, int away_score, char* away_team) {
20
- struct match* ptr;
21
- ptr = (struct match *)malloc(sizeof(struct match));
22
- strcpy(ptr->home,home_team);
1
+ strcpyを用いる質問をしましたが都合により削除することになりました。
23
- strcpy(ptr->away,away_team);
24
- }
25
-
26
- int main() {
27
- char home_team[256], away_team[256];
28
- int home_score, away_score;
29
- int year, month, day, i, f;
30
-
31
- const char* filename = "jleague.txt";
32
- FILE* fp;
33
-
34
- for (i = 0; i < HASHSIZE; i++) {
35
- hashtable[i] = NULL;
36
- }
37
-
38
- fp = fopen(filename, "r");
39
- while ((f = fscanf(fp, "%d %d %d %s %d %d %s", &year, &month, &day, home_team, &home_score, &away_score, away_team)) != EOF) {
40
- add(year, month, day, home_team, home_score, away_score, away_team);
41
-
42
- }
43
-
44
-
45
- }
46
- ```このコードは、与えられたファイルを読みとって、データを取り出すといった内容です。
47
- add関数内にあるstrcpyを使って、char型のhome_teamをそのまま、コピーして構造体変数であるhomeに代入したいと思っておりますが、例外が発生しておりできない状態です。ここでは、エラーの内容では*homeが定義されていないとのことです。
48
- charの同じポインタ変数なので型違いはないと思いますが、ご協力お願いします。

1

内容と異なるコードを出したから

2020/07/08 06:45

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -17,17 +17,10 @@
17
17
 
18
18
 
19
19
  void add(int year, int month, int day, char* home_team, int home_score, int away_score, char* away_team) {
20
- int hashval;
21
20
  struct match* ptr;
22
- hashval=hash(home_team, away_team);
23
21
  ptr = (struct match *)malloc(sizeof(struct match));
24
22
  strcpy(ptr->home,home_team);
25
23
  strcpy(ptr->away,away_team);
26
- ptr->next = hashtable[hashval];
27
- hashtable[hashval] = ptr;
28
- ptr = push(ptr, home_team, away_team);
29
-
30
-
31
24
  }
32
25
 
33
26
  int main() {