如何使用C文件打开功能打开.ttcn文件? [英] How to open .ttcn file using C file open functions?

查看:131
本文介绍了如何使用C文件打开功能打开.ttcn文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究TTCN-3(测试和测试控制符号)脚本语言.我想在准则检查器中为此代码文件做准备.

为此,我想将TTCN-3脚本文件(如file.ttcn之类的东西)一行一行地读取到缓冲区中.但是对我来说,fopen/sopen/open/fgetc/fscanf无法正常工作,并且无法正确读取文件.它给出NULL.有什么办法可以将其字符读入缓冲区.我认为C无法读取具有三个以上扩展名字符(如.ttcn)的文件.如果我的假设是错误的,请原谅我.

I am working on TTCN-3 (Testing and Test Control Notation) scripting language. I wanted to prepare on guideline checker for this code files.

For that I want to read lines of TTCN-3 script file( some thing like file.ttcn ) one by one into a buffer. But for me fopen / sopen / open / fgetc / fscanf are not able to work properly and are not reading the file correctly. It is giving NULL. Is there any way I can read characters of it into a buffer. I think C cannot read files with more than three extension characters (like .ttcn). Forgive me if my assumption is wrong.

我的环境是Windows上的TurboC.

修改:

是的,我也检查了那些错误,但是它们为read()提供了未知错误 并且不存在这样的文件或目录.

我的代码如下

My Environment is Turbo C on windows.

Edit:

Yes I checked those errors also but they are giving unknown error for read() and no such file or directory exists.

My code is as follows

#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;
}

推荐答案

MS-DOS不知道长文件名,因此包括扩展名超过3个字符的文件.因此,Turbo C提供的CRT很可能不是在寻找您提供的名称,而是一个截断的名称-或其他名称.

MS-DOS does not know about long file names, thos including files with extensions longer than 3 characters. Therefore, the CRT provided by Turbo C most probably does not look for the name you are providing, but a truncated one - or something else.

Windows方便地为它们提供了一个简短的文件名(即匹配8.3格式,大多数时间以〜1结尾,除非您使用具有相同的8个字符前缀的文件播放);发现它的一种方法是打开控制台窗口,然后在文件存储的文件夹中运行"dir/x".

Windows conveniently provides a short (i.e. matching the 8.3 format, most of the time ending in ~1 unless you play with files having the same 8-character prefix) file name for those; one way to discover it is to open a console window and to run "dir /x" in the folder your file is stored.

找到与文件关联的简称,并将其修补到C源文件中.

Find the short name associated to your file and patch it into your C source file.

该死,我下次再看评论.所有功劳归j_random_hacker.

Darn, I'll read the comments next time. All credits to j_random_hacker.

这篇关于如何使用C文件打开功能打开.ttcn文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆