質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
C

C言語は、1972年にAT&Tベル研究所の、デニス・リッチーが主体となって作成したプログラミング言語です。 B言語の後継言語として開発されたことからC言語と命名。そのため、表記法などはB言語やALGOLに近いとされています。 Cの拡張版であるC++言語とともに、現在世界中でもっとも普及されているプログラミング言語です。

Q&A

解決済

1回答

2788閲覧

c言語のエラーメッセージ、storage size of 'file' isn't knownの原因と解決方法

yuto_jake

総合スコア42

C

C言語は、1972年にAT&Tベル研究所の、デニス・リッチーが主体となって作成したプログラミング言語です。 B言語の後継言語として開発されたことからC言語と命名。そのため、表記法などはB言語やALGOLに近いとされています。 Cの拡張版であるC++言語とともに、現在世界中でもっとも普及されているプログラミング言語です。

0グッド

0クリップ

投稿2022/05/21 10:03

C言語を使用して、タスク情報を記録できるシステムを作成しています。事前に作成したtxtファイルをdeletetaskのコードを使ってtxtファイルを削除したいのですが、現在書いているコードだとstorage size of 'file' isn't knownが表示されてしまい実行がうまくいきません。以下にソースコード、txtファイルの内容をupしますので、エラーメッセージが出てくる原因と解決方法をご教授いただけますと幸いです。
イメージ説明

c

1#include<stdio.h> 2 3#include<stdlib.h> 4 5#include<conio.h> 6 7#include<string.h> 8 9 10void deletetask(); 11 12struct task 13 14{ 15 16 char time[8]; 17 18 char name[50]; 19 20 char status[100]; 21 22 char category[100]; 23 24 char note[2000]; 25 26} ; 27 28int main() 29 30{ 31 32 int ch; 33 34 printf("\n\n\t---------------------------------\n"); 35 36 37 38 printf("\t---------------------------------"); 39 40 while(1) 41 42 { 43 44 printf("\n\tDelete Task\t[4]"); 45 46 printf("\n\n\tEnter your choice:"); 47 48 scanf("%d",&ch); 49 50 switch(ch) 51 52 { 53 54 case 4: 55 56 deletetask(); 57 58 break; 59 60 case 5: 61 62 printf("\n\n\t\tThank you for using Task manager!!^^"); 63 64 getch(); 65 66 exit(0); 67 68 default: 69 70 printf("\nYou entered wrong choice..."); 71 72 printf("\nPress any key to try again"); 73 74 getch(); 75 76 break; 77 78 } 79 80 system("cls"); 81 82 } 83 84 return 0; 85 86} 87 88void deletetask( ) 89 90{ system("cls"); 91 92 FILE *fp,*fptr ; 93 94 struct record file ; 95 96 char filename[15],another = 'Y' ,time[10];; 97 98 int choice,check; 99 100 printf("\n\n\t\t---------------------------------\n"); 101 102 printf("\t\t* Welcome to the Delete Task Menu *"); 103 104 printf("\n\t\t---------------------------------\n"); 105 106 107 while ( another == 'Y' ) 108 109 { 110 111 printf("\n\n\tHow would you like to delete?"); 112 113 printf("\n\n\t#Delete all tasks\t\t\t[1]"); 114 115 printf("\n\t#Delete a particular record by due date\t[2]"); 116 117 do 118 119 { 120 121 printf("\n\t\tEnter a number:"); 122 123 scanf("%d",&choice); 124 125 switch(choice) 126 127 { 128 129 case 1: 130 131 printf("\n\tEnter the due date of task to be deleted:[yyyy-mm-dd]:"); 132 133 fflush(stdin); 134 135 gets(filename); 136 137 fp = fopen ("task.txt", "wb" ) ; 138 139 if ( fp == NULL ) 140 141 { 142 143 printf("\nThe file does not exist"); 144 145 printf("\nPress any key to go back..."); 146 147 getch(); 148 149 return ; 150 151 } 152 153 fclose(fp); 154 155 remove(filename); 156 157 printf("\nDeleted successfully!"); 158 159 break; 160 161 case 2: 162 163 printf("\n\tEnter the due date of task:[yyyy-mm-dd]:"); 164 165 fflush(stdin); 166 167 gets(filename); 168 169 fp = fopen ("task.txt", "rb" ) ; 170 171 if ( fp == NULL ) 172 173 { 174 175 printf("\nThe file does not exist"); 176 177 printf("\nPress any key to go back..."); 178 179 getch(); 180 181 return ; 182 183 } 184 185 fptr=fopen("task.txt","wb"); 186 187 if(fptr==NULL) 188 189 { 190 191 printf("\nSystem error..."); 192 193 printf("\nPress any key to go back..."); 194 195 getch(); 196 197 return ; 198 } 199 200 printf("\n\tEnter the due date of task to be deleted:[hh:mm]:"); 201 202 fflush(stdin); 203 204 gets(time); 205 206 while(fread(&file,sizeof(file),1,fp)==1) 207 208 { 209 210 if(strcmp(file.time,time)!=0) 211 212 fwrite(&file,sizeof(file),1,fptr); 213 214 } 215 216 fclose(fp); 217 218 fclose(fptr); 219 220 remove(filename); 221 222 rename("task.txt","newtask.txt"); 223 224 printf("\nDeleted successfully!"); 225 226 break; 227 228 default: 229 230 printf("\n\tYou entered wrong choice.."); 231 232 break; 233 234 } 235 236 } 237 while(choice<1||choice>2); 238 239 printf("\n\tDo you want to delete another record?(Y/N):"); 240 241 fflush(stdin); 242 243 scanf("%c",&another); 244 245 } 246 247 printf("\n\n\tPress any key to exit"); 248 249 getch(); 250 }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

record が定義されていません。 結果的に file が何者であるかわからないので file の大きさもわかりません。

投稿2022/05/21 10:37

SaitoAtsushi

総合スコア5437

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

pepperleaf

2022/05/22 00:44

で、エラーが出ているので、コンパイルが通らないと思う、、、と質問への追記を入れたが、なぜか消えている。 ... とこちらに書いてみます。(質問は、実行時エラーのような記述)
yuto_jake

2022/05/23 07:20 編集

SaitoAtsushiさん、ご回答ありがとうございます。 原因は理解できたのですが、recordの定義をどの行に追加したらよいのでしょうか?ご教授いただければと思います。
yuto_jake

2022/05/23 07:08

pepperleafさん、コメントありがとうございます。 私にも原因がわかりませんが、質問が消えていますね。。 ご説明ありがとうございます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問