how can I erase a array?
what the syntax? I can't find anywere... I only find when we declare the array.Code:char array[150]; loopA{ loopB{ do work over array; } //I need to erase his value to the next loop array[] = ""; //didn't work! }
how can I erase a array?
what the syntax? I can't find anywere... I only find when we declare the array.Code:char array[150]; loopA{ loopB{ do work over array; } //I need to erase his value to the next loop array[] = ""; //didn't work! }
i think you should use pointers for this
Code:char *array=malloc(150 *sizeof(int)); //do your work then free(array);
There's no such thing as "erase". Do you mean set all the elements of the array to 0? Try this:
Make sure include the appropriate header for memset().Code:memset(array, 0, sizeof(*array) * sizeof(array));
If you understand what you're doing, you're not learning anything.
converting to a pointer, I'll be able to do something like this?
thanks!Code:char *array=malloc(150 *sizeof(int)); char HStr[2000]; while ((HStr[j] != '}') || (HStr[j]=='\0')){ array[i] = HStr[j]; i++;j++; }
An array's size given by sizeof(), if it's an array, is the size in bytes. Therefore, the memset() example given above is incorrect. If array is a real array, then it'll setting too much memory. Otherwise, if it's just a pointer to a malloc()'ed block of memory, it stands a chance of setting too little memory.
if you're using "array" as a null-terminated character array (which some would loosely refer to as a string), then all you need to do is set the first character to null:Code:array[0] = '\0';
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"