开发者

String array is not reading in the value? [closed]

开发者 https://www.devze.com 2023-03-26 09:07 出处:网络
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.

This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.

Closed 8 years ago.

Improve this question

In the Second while loop the data in string is there i checked "data added" however when i stepin and check what string[walker + *len] it constantly has NUL ('\0') even after len is increment? What is the error here ?!?

char* getWord(char* string, short* len)
{
 size_t walker = 0;

  /*POINT TO THE FIRST CHAR*/
  while (string[walker] == ' ' ||开发者_如何学编程 string[walker] == '\0')
   ++walker;


 while ( string[walker + *len] != ' ' || string[walker + *len] != '\0'  )
   ++(*len);

 return (&string[walker]);


You have a few logic bugs there - it should be something like this:

char* getWord(char* string, short* len)
{
  size_t walker = 0;
  *len = 0; // << initialisation of *len

  /*POINT TO THE FIRST CHAR*/
  while (string[walker] == ' ') // << remove incorrect check for end of string
    ++walker;

  while (string[walker + *len] != ' ' && string[walker + *len] != '\0') // << fix logic for testing for space or end of string
    ++(*len);

  return &string[walker];
}


Are you sure that *len is 0 when you call your function? Don't you need to initialize it? Also, in the second while condition I'd guess that you want to use a && rather than ||.

0

精彩评论

暂无评论...
验证码 换一张
取 消