我有一个简单的 C 代码如下:
#pragma warning(disable : 4996)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <process.h>
#include <math.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <windows.h>
#include <tchar.h>
int main()
{
int ndsc;
char *line = ' ';
FILE *fd;
int x;
wchar_t path[256];
wcscpy(path, L"C:/");
//wcscat(path, L"common\\descr.txt", wcslen(L"common\\descr.txt"));
//Previous
wcscat(path, L"common/descr.txt");
if ((fd = _wfopen(path, L"r")) == NULL)
{
printf("Can't open %s for reading.\n", path);
return 1;
}
for (ndsc = 0; fgetws((wchar_t*)line, 80, fd) != NULL; ndsc++)
{
x = wcslen((const wchar_t*)line);
printf("Length of %d line is %d\n", ndsc, x);
}
fclose(fd);
return 0;
}
我正在尝试从 C:\Common 目录中读取一个名为 descr.txt 的文件。但在 for 循环中,它会抛出未处理的异常,如下所示:
谁能解释我为什么会收到此错误以及如何解决。顺便说一句,此代码正在 AutoCad 的 .arx 文件中使用。我刚刚提取了抛出错误的部分,并尝试在 VS 2015 Update 3 中将其作为独立项目运行。此代码是从 .NET 调用的 .C 文件的一部分。即使在 .arx 的上下文中执行(从 AutoCad 单击所需菜单)也会出现相同的异常。
提前致谢。