不知道如何解决错误

时间:2019-06-04 08:30:14

标签: c file format scanf srt

我正在使用fscanf扫描格式化的.srt文件,但是由于遇到了C语言,我遇到了无法解决的问题。

我试图逐字符读取文件char,但是结果却变成了我无法调试的大混乱

if (input == NULL) 
    {
        printf("File doesn't exist, exiting!\n");
        exit(1);
    }
    printf("File opened!\n");

    int order; //number of line

    int csh; //hh
    int csm; //mm
    int css; //ss
    int csms; //ms

    int ceh; // same order as above
    int cem;
    int ces;
    int cems;

    char* text = calloc(256, sizeof(char));
    char c;

    int count = 0;
    while ((i = fscanf(input, "%d\n%d:%d:%d,%d --> %d:%d:%d,%d\n%10s", &order, &csh, &csm, &css, &csms, &ceh, &cem, &ces, &cems, text) > 0) )
    {
        count++;
        printf("%d\n%d:%d:%d,%d --> %d:%d:%d,%d\n%s",  order,  csh, csm, css,  csms,  ceh,  cem,  ces,  cems, text);

if (count == 2) 
        {
            int xyx;
            scanf_s("%d", &xyx);
        }




    }

因此,我尝试读取格式化的文件并将数据存储在双链表中,并且文件看起来像这样

http://sqlfiddle.com/#!9/3bed7b/1

等等我相信File是一个巨大的幻影威胁的完整字幕,所以我有两个问题,我的代码在完成时间后无法读取整个文本,其次,它没有超过我使用的2的计数器只是为了测试程序。

我得到这个输出 enter image description here

1 个答案:

答案 0 :(得分:-1)

Mathieu的评论给了我一个线索,我为此解决了问题:

while (i = fgetc(input) != EOF) 
    {
        while ((i = fscanf(input, "%d\n%d:%d:%d,%d --> %d:%d:%d,%d\n%[^'']", &order, &csh, &csm, &css, &csms, &ceh, &cem, &ces, &cems, text) > 0))
        {

            printf("%d\n%d:%d:%d,%d --> %d:%d:%d,%d\n%s\n", order, csh, csm, css, csms, ceh, cem, ces, cems, text);



        }
    }
相关问题