开发者

simple C++ comparision if statement

I have a function in C++ that takes a char array thingArray[6] and places ' ' onto each place.

like:

   for (int i =0; i<5; i++)
   {
       thingArray[i] = ' ';
   }

now I have another function that sticks a character if it finds an empty space in the array. please say the array now looks like: 'w',' ','R','E',' ','E',

if I do:

for (int i = 0;i<5;i++)
{
     if (thingArray[i] == ' ')
     {
         thingArray[i] = 'M';
     }
}

It should be pretty intuitive that the for loop will traverse the array and find the ' ' and stick an 'M' in it's place. Sometimes it will not work. This is my first time coding in a language that uses pointers so I think that may be one of my开发者_开发技巧 issues.

Any suggestions, or a better way of doing this would be great!

Thanks.


If thingArray is a string literal, then it's actually constant and you can't change the value of its elements.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜