-4

For the life of me I can't figure out how to do this. I thought I could use memset() but I'm getting a segmentation fault.

char **a;
token = strtok( NULL, " " );
if( token != NULL )
    strcpy( token, strtok( token, "\n" )); // get rid of '\n' at end if it exists
else{  
    // I want to reset all the values in a to null 
    return;
} 

I thought I could even just do a while loop like while(a[i] != 0 ) set each element to 0, but even then I'm getting a segmentation fault. This should be easy right? What am I doing wrong?

hmjd
  • 120,187
  • 20
  • 207
  • 252
Matthew The Terrible
  • 1,589
  • 5
  • 31
  • 53

1 Answers1

2

Your initial call to strtok() should NOT be done with a NULL argument as the first parameter!

Check the reference:

http://www.cplusplus.com/reference/cstring/strtok/

What exactly are you trying to achieve?

Forhad Ahmed
  • 1,761
  • 13
  • 18