字符分割交换

#include 
#include 
#define FILENAME "C:/Users/Administrator.USER-20160813YZ/Desktop/33.txt"
void test()
{
    FILE *fp=fopen("C:/Users/Administrator.USER-20160813YZ/Desktop/33.txt", "w");
    fputs("111;xx1;[email protected]\n", fp);
    fputs("112;xx2;[email protected]\n", fp);
    fputs("113;xx3;[email protected]\n", fp);
    fclose(fp);
}
/*
 1.将信息读取到内存
 2.去掉\n
 3.分割字符串
 4.交换字符串
 5.写文件
 */

void mySplit(char *str,char ch,char *pre,char *next)
{
    while (*str!=ch)
    {
        *pre=*str;
        str++;
        pre++;
    }
    *pre='\0';
    
    str++;//移到;后面
    while(*str!='\0')
    {
        *next=*str;
        next++;
        str++;
    }
    *next='\0';
}



void swapString(char *str)
{
    char others[20];
    char string1[20],string2[20],string3[20];
    mySplit(str, ';', string1, others);
    mySplit(others, ';', string2, string3);

    strcpy(str, string2);
    strcat(str, ";");
    strcat(str, string3);
    strcat(str, ";");
    strcat(str, string1);
    strcat(str, "\n");
//    printf("拼接好的str=%s\n",str);
}

void removeEnter(char text[][100],int index)
{
    int i=0;
    for (; i

你可能感兴趣的:(字符分割交换)