You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS2019编译C代码报unexpected end of file found错误如何解决

问题根因与修复方案

核心错误点

你遇到的unexpected end of file found报错是预处理器解析失败导致的,直接原因有2个:

  • test.h引用了C++专属头文件<cstddef>,C语言编译器无法识别该头文件,解析中断
  • 两个.c文件的#include语句使用了中文双引号“test.h”,预处理器无法识别中文标点,无法正确定位头文件触发解析错误

另外你的代码还存在后续会触发编译错误的问题:

  • C语言大小写敏感,test.c中结构体类型名定义为小写students,函数实现时错写为大写Students
  • test.c中anothernewfunction的返回值错写为大写Void,C语言关键字均为小写
  • 函数名new是C++保留关键字,即便C编译可通过,也建议改名避免后续兼容问题

修复步骤

  1. 修正test.h的头文件引用
    将#include <cstddef>替换为C标准头文件:
#include <stddef.h>
  1. 替换所有#include后的中文双引号为英文半角双引号"
  2. 修正test.c的大小写错误:
  • Students*new()改为students* new()
  • Void anothernewfunction()改为void anothernewfunction()
  1. 建议将new函数重命名为new_students避免关键字冲突

修正后完整代码

test.h

//test.h 
#ifndef __test_h
#define __test_h
#include <stddef.h>
typedef struct
{
  float a; 
  float b;
}students;

students* new_students();
void newfunction();
void anothernewfunction();
#endif

test.c

//test.c 
#include "test.h"

students* new_students()
{
    // 补充返回逻辑避免编译警告
    return NULL;
}

void newfunction()
{}

void anothernewfunction()
{}

testmain.c

//testmain.c
#include "test.h"
int main()
{
    return 0;
}

内容的提问来源于stack exchange,提问作者P Pp

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 12:48:00