在C语言中,可以使用fopen函数来打开文件。fopen函数的原型为:
FILE *fopen(const char *filename, const char *mode);其中,filename是要打开的文件的名称,mode是打开文件的模式。常用的模式包括:
示例代码如下:
#include <stdio.h>int main() { FILE *file = fopen("example.txt", "r"); if (file == NULL) { printf("Failed to open file.\n"); return 1; } // 读取文件内容或进行其他操作 fclose(file); // 关闭文件 return 0;} 

