0

I want to split a string with "." separator in C. For example, I have a string like this "studentdetails.txt". Now I want to result like this "studentdetails" and "txt". Please give me any idea to do it.

2 Answers2

1

You may know about strtok in C.

Ex.

char str[] = "studentdetails.txt";
char delims[] = ".";
char *result = NULL;
result = strtok( str, delims );
while( result != NULL ) {
    printf( "%s\n", result );
    result = strtok( NULL, delims );
}
Jayesh Bhoi
  • 24,694
  • 15
  • 58
  • 73
0

You can use a strtok() function.

char str[] ="This is a sample string, just testing.";
char *p;

printf ("Split \"%s\" in tokens:\n", str);

p = strtok (str," ");

while (p != NULL)
{
    printf ("%s\n", p);
    p = strtok (NULL, " ,");
}
return 0;

I have used a space... just use "." instead

Jay Nirgudkar
  • 426
  • 4
  • 18