Home > Back-end >  Simple char * data assignment problem! O god!
Simple char * data assignment problem! O god!

Time:09-27

Int NameValueList: : getIndex (const char * name) const {

Char * the_name;
Strncpy (the_name, name, MAX_NAME_LENGTH);//why this char * data cannot be called directly, need to create a space to copy the past again call?

for(int i=0; IIf (STRCMP (the_name, names [I])==0)//why do you want to create a new the_name, cannot directly call name
return i;
return -1;
}

CodePudding user response:

The code you provide incomplete, unable to judge,

CodePudding user response:

You have a problem of the code above, the_name is a null pointer, the following use strncpy to write, this program will collapse! And didn't check the incoming pointer is null, and the const type is not can't use just said can't modify,

CodePudding user response:

Are based or look at a book club
  • Related