c - C中的异常读取位置

标签 c autocad objectarx

我有一个简单的 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 循环中它会抛出未处理的异常,如下所示:

Unable to read memory

Exception

任何人都可以解释一下为什么我会收到此错误以及如何解决。 顺便说一句,此代码正在 AutoCad 的 .arx 文件中使用。我刚刚提取了引发错误的部分,并尝试将其作为 VS 2015 Update 3 中的独立项目运行。此代码是 .NET 调用的 .C 文件的一部分。即使在 .arx 上下文中执行(从 AutoCad 单击所需菜单)也会出现相同的异常。

提前致谢。

最佳答案

此处:char *line = ' '; 您将 char 分配给 char *

稍后您尝试使用宽字符串缓冲区。您需要 wchar_t line[80] 来实际为 80 个 wchar_t 分配空间。

关于c - C中的异常读取位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45505948/

相关文章:

c# - 有没有更快的方法来调试 ObjectARX 应用程序?

直接映射缓存的 C 缓存优化

c - C函数中的指针到指针;链表

c# - 尝试使用 Autodesk.AutoCAD.DatabaseService 从 DWG 中读取数据 我需要引用什么 DLL?

c# - AutoCAD resbuf 迁移

autocad - 在accoreconsole.exe中加载自定义.net dll

c++ - 线程和系统信号

c - 如何使指针指向两个或多个连续的单元格

html - 在 HTML 中嵌入 DWG 文件

command-line-interface - 仅从命令行运行 AutoCAD