0

Hello

I have a list of data, which looks something like below
www.clickajob.co.uk%2Fprofiles%2F316%2F6%2F|a/TLT10911641168.google
www.ukdata.com%2Fcompany-listings%2FAd-16.html|a/TLT10911767856.google

I need to parse this data so i am left with

www.clickajob.co.uk|TLT10911641168.google
www.ukdata.com|TLT10911767856.google

Does anyone know how to help me? I have the following so far

if ( fp == NULL )
    {
        printf("Error opening %s\n", filename );
        return(1);
    }
    printf("Sucessfully opened %s\n", filename );

    while(fgets(string,sizeof(string), fp )!= NULL )
    {
         printf("Start = %s\n", string );
         if( ptr = strtok(string,"%"))
         {
             memcpy(web,ptr,sizeof(web));
             printf("web = %s\n", web );
             if ( ptr = strtok(NULL,"|" ))
             {
                 printf("ptr = %\n", ptr );
                 memcpy(Company,ptr,sizeof(Company));
                 printf("BURN = %\n", Company );
             }
         }
    }
2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by Ancient Dragon
0

If the strings are always in that exact format than this should work.

int main()
{
    char s1[] = "www.clickajob.co.uk%2Fprofiles%2F316%2F6%2F|a/TLT10911641168.google";
    char s1a[50] = {0};
    char* pos;

    pos = strchr(s1,'%');
    *pos++ = 0;
    strcpy(s1a, s1);
    pos = strchr(pos,'/');
    strcat(s1a,"|");
    strcat(s1a,pos+1);
    printf("%s\n", s1a);
    return 0;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.