我正在研究 TTCN-3(测试和测试控制符号)脚本语言。我想为这个代码文件准备指南检查器。
为此,我想将 TTCN-3 脚本文件(类似 file.ttcn 的内容)一行一行地读入缓冲区。但对我来说 fopen/sopen/open/fgetc/fscanf 无法正常工作并且无法正确读取文件。它给出 NULL。有什么办法可以将它的字符读入缓冲区。我认为 C 无法读取扩展名超过三个的文件(如 .ttcn)。如果我的假设是错误的,请原谅我。
我的环境是 Windows 上的 Turbo C。
编辑:
是的,我也检查了这些错误,但它们给出了 read() 的未知错误 并且不存在这样的文件或目录。
我的代码如下
#include <errno.h>
#include <io.h>
#include <fcntl.h>
#include <sys\stat.h>
#include <process.h>
#include <share.h>
#include <stdio.h>
int main(void)
{
int handle;
int status;
int i=0;
char ch;
FILE *fp;
char *buffer;
char *buf;
clrscr();
handle = sopen("c:\\tc\\bin\\hi.ttcn", O_BINARY, SH_DENYNONE, S_IREAD);
/这里我什至使用了 O_TEXT 和其他/
if (!handle)
{
printf("sopen failed\n");
// exit(1);
}
printf("\nObtained string %s @",buf);
close(handle);
fp=fopen("c:\\tc\\bin\\hi.ttcn","r"); \\sorry for the old version of one slash
if(fp==NULL) \\I was doing it with argv[1] for opening
{ \\user given file name
printf("\nCannot open file");
}
ch=fgetc(fp);
i=0;
while(i<10)
{
printf("\ncharacter is %c %d",ch,ch);
i++; //Here I wanted to take characters into
ch=fgetc(fp); //buffer
}
getch();
return 0;
}
最佳答案
最有可能的罪魁祸首是您的 Turbo C,一个古老的编译器。它在技术上是 DOS 编译器,而不是 Windows。这会将它的 RunTme 库限制为 8.3 文件名。升级到更新的东西 - Turbo C++ 似乎是合乎逻辑的继任者,但 Microsoft 的 VC++ Express 也可以。
关于c - 如何使用 C 文件打开函数打开 .ttcn 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/515171/