I use a smaller part of the code to test the functionality for a larger (beginner) program, but I do not understand the difference between the two lines.
I found and used:
#include <stdio.h>
#include <string.h>
int main()
{
char *string, *found;
string = strdup ("1/2/3");
printf("Orig: '%s'\n",string);
while ((found = strsep(&string,"/")) != NULL )
printf ("%s\n",found);
return (0);
}
and it prints the markers one at a time.
Then, when I try to jump to the line entered by the user:
#include <stdio.h>
#include <string.h>
int main()
{
char string[13],
char *found, *cp = string;
fprintf(stderr, "\nEnter string: ");
scanf("%12s",string);
printf("Original string: '%s'\n",string);
while((found = strsep(&cp,"/,-")) != NULL )
printf("%s\n",found);
return(0);
}
I get a seg error. I understand the basics of pointers, arrays, and strings, but obviously I'm missing something and would like someone to tell me what it is!
Also - if I change printf("%s\n",found);to printf("%i\n",found);, I get the returned returned integers, but always the right amount, for example. If I enter 1/2/3, I get three lines of integers, 1111/2222I get two lines.
Thank!
-Edit-
strsep, . .