how to do this like it should ??


I'm starting to learn how to program in c++.
I use now
for (inti=0,i<20,i++){string[i]=0x00;}
to "reset" a string to zero.

How is the correct way to do that ?

Who is Participating?
Jaime OlivaresConnect With a Mentor Software ArchitectCommented:
Andrey_go answer will be enough, assumming you are working with a char array (I guess it is because 'string' name), because in stardard C, all string are zero-terminated.

string[0]=0;  could be simplified to:
*string = 0;

'string' is not a good name because there is some library called STL that uses a data type called string.
Andrey_goConnect With a Mentor Commented:
string[0]=0; should be enough
use a char array, instead of string.

The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

lapijnAuthor Commented:
thanks teuntje.
lapijnAuthor Commented:
OK, jaime_olivares. Thanks all.
All Courses

From novice to tech pro — start learning today.