テキスト ファイルから読み込んで書き込もうとしていますが、コードを実行するたびにテキスト ファイルに何も起こりません。「何も起こらない」とは、プログラムが入力ファイルを読み取らず、出力ファイルにデータがエクスポートされないことを意味します。なぜそれが機能しないのか誰かが指摘できますか?事前に助けてくれてありがとう。これが私のコードです:
#include <stdio.h>
#include <stdlib.h>
FILE *inptr, *outptr;
int main() {
int a, b, c;
inptr = fopen("trianglein.txt","r"); //Initialization of pointer and opening of file trianglein.txt
outptr = fopen("triangleout.txt","w"); //Initialization of pointer and opening of file triangleout.txt
while((fscanf(inptr,"%d %d %d",&a, &b, &c))!= EOF){
fprintf(outptr,"\n%2d %2d %2d\n",a,b,c);
if(a+b>c && b+c>a && c+a>b){
fprintf(outptr, "This is a triangle.\n");
if(a !=b && b !=c && a!=c){
fprintf(outptr, "This is a scalene triangle.\n");
if(a==b && a==c && c==b){
fprintf(outptr, "This is an equilateral triangle.\n");
if(a*a+b*b==c*c || b*b+c*c==a*a || a*a+c*c==b*b){
fprintf(outptr, "This is a right trianlge.\n");
}
}
}
}
}
return 0;
}
trianglein.txt
コンテンツ:
10 12 15
2 3 7
3 4 5
6 9 5
6 6 6
6 8 10
7 7 9