Tuesday, July 14, 2009

Need help with pointers in C?

How would I write this and why isn't it working?





I have a pointer pointing to the first character in a string. I want to store this string to the first entry in a two-dimensional array called "paths". Why isn't my loop storing the string?





char* token;


while (token != NULL)


{


paths[ 0 ][ j ] = %26amp;token;


token++;


j++;


}

Need help with pointers in C?
You didn't assign token to anything. Also, you appear to be confusing address %26amp; with object pointed to *.





char szMystring[] = "I have a problem.";


char* token;


char paths[2][64];





token = %26amp;szMystring[0];


int j = 0;


while (*token != 0)


{


paths[ 0 ][ j ] = *token;


token++;


j++;


}

salary survey

No comments:

Post a Comment