我试图从一个文本文件中读取并写入一个,但是每次我执行我的代码时,文本文件都没有发生任何事情。“什么都没有发生”,我的意思是程序不会读取我的输入文件,也没有数据导出到我的输出文件中。有人可以指出为什么它不起作用吗?感谢您提前提供的任何帮助。这是我的代码:
#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