alright it worked now but i got now one problem left that end doesnt specify anything

Right:

To modify a pointer in a called function, you'll need to pass a pointer to it (a pointer to a pointer).

#include <stdio.h>
#include <string.h>

int ParseCh(char *S,char *buff,int num,char **End) {
    int i,temp=0;
    for(i=0;S[i]!=0;i++) {
        if(S[i]==',' || S[i]=='\n' || S[i]=='\t' || i==num) {
            puts("found it");
            temp=1;
            *End=&S[i]+1;
            S[i]=0;
            break;
        }
    }
    if(temp)
        strcpy(buff,S);
    else {
        *End=0;
        i=0;
    }
    return i;
}
int main(void)
{
    char Name2[]="NAME,M";
    char Name[10]={0};
    char *End;//last string after the , or new lines etc if its initlised to 0 it means there was no , new lines or tab inside the string
    ParseCh(Name2,Name,5,&End);
    printf("Name after being parsed %s and it ended at %s\n",Name,End);
    return 0;
}

wow but why though even though its a character ptr why need char pointer to a pointer since 1 pointer can hold the address of a string ?

Called functions receive copies.

#include <stdio.h>
#include <string.h>

void foo(int x)
{
    x += 10;
}

void bar(char *x)
{
    x += 10;
}

int main(void)
{
    char text[] = "hello world";
    char *ptr = text;
    int i = 5;
    printf("before: i = %d, ptr = %p\n", i, ptr);
    foo(i);
    bar(ptr);
    printf("after:  i = %d, ptr = %p\n", i, ptr);
    return 0;
}

/* my output
before: i = 5, ptr = 0022FF60
after:  i = 5, ptr = 0022FF60
*/

[edit]

#include <stdio.h>
#include <string.h>

void foo(int x)
{
    x += 10;
}

void bar(char *x)
{
    x += 10;
}

void baz(int *x)
{
    *x += 10;
}

void qux(char **x)
{
    *x += 10;
}

int main(void)
{
    char text[] = "hello world";
    char *ptr = text;
    int i = 5;
    printf("before: i = %d, ptr = %p : %s\n", i, ptr, ptr);
    foo(i);
    bar(ptr);
    printf("mid:    i = %d, ptr = %p : %s\n", i, ptr, ptr);
    baz(&i);
    qux(&ptr);
    printf("after:  i = %d, ptr = %p : %s\n", i, ptr, ptr);
    return 0;
}

/* my output
before: i = 5, ptr = 0022FF60 : hello world
mid:    i = 5, ptr = 0022FF60 : hello world
after:  i = 15, ptr = 0022FF6A : d
*/

oh thanks alot man nice info for that char ** didnt know abt it thanks guys for your help again don't know what i have done without u.

sorry for the post..actually i posted it before visiting page 2..so editied it....!!

IGNORE THIS..

thanks...!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.