1998-c-三

/*
    算法思想:打开文件、按格式读入文件、
    统计歌名以及演唱者的字符长度、重新拼接写入新文件
*/
#include <stdio.h>
#define N 10
#define M 3
#define maxSize 100

int main()
{
    FILE *fin,*fout;//定义读入指针以及写指针
    char song[maxSize];
    char singer[maxSize];
    int len1,len2;
    char str1[maxSize];
    char str2[maxSize];
    char str3[maxSize];

    if((fout=fopen("NewSong.txt","w"))==NULL)//打开失败
        printf("open out error");
    if((fin=fopen("song.txt","r"))==NULL)//打开失败
        printf("open in error\n");
    else//打开成功
    {
        while(!feof(fin))
        {
//            fscanf(fin,"%Ns%Ms",song,singer);//此处无法使用宏常量,具体原因不明
            fscanf(fin,"%10s%3s",song,singer);
            fprintf(fout,"%d",strlen(song));
            fprintf(fout,"%d",strlen(singer));
            fprintf(fout,"%s",song);
            fprintf(fout,"%s",singer);
        }
        fclose(fin);
        fclose(fout);
    }
}