首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

文本转换有关问题

2013-10-22 
文本转换问题0.5If you are a premiere member of the lynda.com online training library, or if you5.

文本转换问题


0.5">If you are a premiere member of the lynda.com online training library, or if you

5.19">are watching this tutorial on a DVD, you have access to the exercise files used throughout the title.

如何将上面的文本转化为下面的文本格式
我写了一个对话框程序,fopen 了 然后fread不出来,大家有没有好一点的方法

1
00:00:00,500 --> 00:00:05,190
If you are a premiere member of the lynda.com online training library, or if you

2
00:00:05,190 --> 00:00:11,800
are watching this tutorial on a DVD, you have access to the exercise files used throughout the title.


下面附上一段代码(选取文件和得到文件名字的功能):
TCHAR szFilter[]=_T
("文本文件(*.txt)|*.txt|所有文件(*.*)|*.*||");
CFileDialog   dlg(TRUE,NULL,NULL,OFN_FILEMUSTEXIST|OFN_HIDEREADONLY, szFilter);    

if   (dlg.DoModal()==IDOK) 
{   
edit1 =  dlg.GetPathName();  
fileName = dlg.GetFileTitle();
SetWindowText(fileName);

SetDlgItemText(IDC_EDIT1,edit1); 
UpdateData(FALSE); 
        }

[解决办法]
加第48行后:
//文本文件in.txt,格式:
//0.5">If you are a premiere member of the lynda.com online training library, or if you
//
//5.19">are watching this tutorial on a DVD, you have access to the exercise files used throughout the title.
//
//11.8">
//转为文本文件out.txt格式:
//1
//00:00:00,500 --> 00:00:05,190
//If you are a premiere member of the lynda.com online training library, or if you
//
//2
//00:00:05,190 --> 00:00:11,800
//are watching this tutorial on a DVD, you have access to the exercise files used throughout the title.
//
#include <stdio.h>
#include <string.h>
#include <math.h>
char fileName[256]="in.txt";
char ln1[4096],*p1;
char ln2[4096];
int n1,n2,i;
double t1,t2;
int main() {
    FILE *fi,*fo;
    fi=fopen(fileName,"r");
    if (NULL==fi) {
        printf("CAn not open file %s\n",fileName);
        return 1;
    }
    i=0;
    fo=fopen("out.txt","w");
    if (NULL==fgets(ln1,4096,fi)) goto SKIP;
    if (1!=sscanf(ln1,"%lf">%n",&t1,&n1)) goto SKIP;
    p1=ln1+n1;
    while (1) {
        if (NULL==fgets(ln2,4096,fi)) break;
        if (1==sscanf(ln2,"%lf">%n",&t2,&n2)) {
            i++;
            fprintf(fo,"%d\n%02d:%02d:%02d,%03d --> %02d:%02d:%02d,%03d\n%s\n",
                i,
                (int)floor(t1)/3600,(int)floor(t1)/60%60,(int)floor(t1)%60,(int)((t1-floor(t1))*1000.0),
                (int)floor(t2)/3600,(int)floor(t2)/60%60,(int)floor(t2)%60,(int)((t2-floor(t2))*1000.0),
                p1
            );
            strcpy(ln1,ln2);
            p1=ln1+n2;
            t1=t2;
        }
    }
SKIP:
    fclose(fo);
    fclose(fi);
    return 0;
}

热点排行