【发布时间】:2013-12-11 04:42:33
【问题描述】:
所以我有这个代码:
#include <stdio.h>
#include <stdlib.h>
#define MASK 0x07FF
#define TABLE_SEZE 32
#define LITTLE_SIZE 8
#define SIZE 256
#define DEBUG 1
int main() {
unsigned v_addr = 0;
FILE *inFilePtr = NULL;
FILE *outfilePtr = NULL;
char inFileName[SIZE];
char outfileName[SIZE];
printf("Enter the name of the file we are working with!.\n");
fgets(inFileName, sizeof(inFileName), stdin);
//open 'er up
inFilePtr = fopen(inFileName, "r");
outfilePtr = fopen(outfileName, "w");
if (inFilePtr == NULL || outfilePtr == NULL){
printf("Could not open the file.\n");
exit(1);
}//end of if
}//end main
我想让它读取一个文件,但它一直说文件不存在。
问题是,文件在当前目录中。怎么回事?
【问题讨论】:
-
您要读取的文件在哪里?它应该在应用程序路径中。
-
你在哪里设置
outfileName?您怎么知道错误是什么,无论实际错误如何,您都会打印相同的消息。使用例如strerror获取实际错误。哦,你甚至不知道 哪个fopen失败了,至少有一个失败了。 -
当您使用它时,我认为
getcwd()可能会告诉您一些信息。 -
与文件在同一目录下。