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

回答編集履歴

1

特に意味はなし

2019/12/08 12:07

投稿

vectorcc
vectorcc

スコア14

answer CHANGED
@@ -23,9 +23,9 @@
23
23
  int **h;//全体
24
24
  int h_size=16;//縦の初期サイズ
25
25
  if((fp=fopen(fname,"r"))==NULL)
26
- exit(-1);
26
+ return NULL;
27
27
  if((h=(int**)calloc(sizeof(int*),h_size))==NULL)
28
- exit(-1);
28
+ return NULL;
29
29
  y=0;
30
30
  while(fgets(buf,256,fp)>0)
31
31
  {
@@ -49,13 +49,14 @@
49
49
  if(y==h_size)
50
50
  {
51
51
  if((h=realloc(h,sizeof(int*)*h_size*2))==NULL)
52
- exit(-1);
52
+ return NULL;
53
53
  else
54
54
  for(i=h_size;i<=h_size*2;i++)
55
55
  h[i]=NULL;//獲得した領域を初期化
56
56
  h_size*=2;
57
57
  }
58
58
  }
59
+ fclose(fp);
59
60
  return h;
60
61
  }
61
62
  void free_matrix(int **h)