Ç - 尝试回到previous行的文件中 [英] C - Trying to go back to previous line in the file

查看:123
本文介绍了Ç - 尝试回到previous行的文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要读,还可选配注释以文本文件。在实践中我在不与开始文件@或>的开头跳过任何线。
在我的测试情况下,文件看起来像:

I have to read a text file which can begin with optional comments. In practice I have to skip any line at the beginning of the file that doesn't begin with '@' or '>'. In my test case the file looks like:

# Sun Jul 12 22:04:52 2009 /share/apps/corona/bin/filter_fasta.pl --output=/data/results/solid0065/primary.20090712170542775 
# Cwd: /state/partition1/home/pipeline
# Title: solid0065_20090629_FC1_Tomate_Heinz_4_5_Kb_Tomate_Heinz_4_5_Kb_01
>125_963_316_F3
T1230330231223011323010013



所以我要跳过第一3号线(但一般我都跳过n行)。我有2个或4档[这是内部文件** inputFiles]重复这一点。我试着用这个循环:

So I have to skip the first 3 line (but in general I have to skip n lines). I have to repeat this with 2 or 4 files [which are inside FILE** inputFiles]. I've tried with this loop:

buffer = (char*) malloc (sizeof(char) * 5000);
if (buffer == NULL)
    notEnoughMemory();

for (i = 0; i < (cIn-1); i++){
    fgetpos(inputFiles[i], &position);
    fgets(buffer, 4999, inputFiles[i]);
    while ((buffer[0] != '@') && (buffer[0] != '>')){
        fgetpos(inputFiles[i], &position);
        fgets(buffer, 4999, inputFiles[i]);
    }
    fsetpos(inputFiles[i], &position);
}



在哪里CIN是number_of_input_files + 1。
试图调试它的循环正常停止它读取第四行之后。但是当我使用它setpos不回去,因为我所期望的第四行的开始,但在第三个中间。
事实上,如果,到底后fsetpos(),我打印这些操作后,缓冲区:

Where cIn is number_of_input_files + 1. Trying to debug it the loop correctly stops after it reads the fourth line. But when I use setpos it doesn't go back to the beginning of the fourth line as I'd expect, but at the middle of the third. In fact if, exactly after the fsetpos(), I print buffer after these operations:

fgets(buffer, 4999, inputFiles[i]);
fgets(buffer, 4999, inputFiles[i]);

我得到:

FC1_Tomate_Heinz_4_5_Kb_Tomate_Heinz_4_5_Kb_01
>125_963_316_F3

你知道吗?
在此先感谢

Any idea? Thanks in advance

推荐答案

您可以直接跳过处理你是不是在interrested行:

You could just skip processing the lines you are not interrested in:

for (i = 0; i < (cIn-1); i++){

    while (fgets(buffer, 4999, inputFiles[i])){
       if(buffer[0] == '@' || buffer[0] == '>') {
          puts(buffer);
        }
        /* else do nothing*/
    }
}

然后你只需替换看跌期权(缓冲); 与code你需要处理的有效行。
(allthough,从你的例子,它听起来就像你更希望只忽略开始行的?)

Then you just replace the puts(buffer); with the code you need to handle the valid lines. (allthough, from your example it sounds like you rather want to only ignore lines starting with a #, ?)

这篇关于Ç - 尝试回到previous行的文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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