文本转换问题

huairui008 2013-10-21 02:15:10

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);
}
...全文
76 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
huairui008 2013-10-21
  • 打赏
  • 举报
回复
谢谢!
赵4老师 2013-10-21
  • 打赏
  • 举报
回复
加第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;
}
赵4老师 2013-10-21
  • 打赏
  • 举报
回复
//文本文件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;
        }
    }
SKIP:
    fclose(fo);
    fclose(fi);
    return 0;
}

64,649

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧