954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

to clear a string

i want to clear a string after the prog. has done it`s work.
i tried it by using a for loop and assigning a blank, but it didn`t work.
the problem is that if i run the program again then the earlier value is displayed again .
i`m using Turbo c++.

varunrathi
Light Poster
41 posts since Aug 2004
Reputation Points: 10
Solved Threads: 1
 

Assign the first element a '\0'. If you're a masochist, use memset on the whole char array.

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

not working

varunrathi
Light Poster
41 posts since Aug 2004
Reputation Points: 10
Solved Threads: 1
 
not working


post code. or not helping.

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

char array="food";
You can use delete[]array to clear the memory

hinduengg
Junior Poster in Training
88 posts since Jun 2007
Reputation Points: 36
Solved Threads: 4
 

No you can't. You can only 'delete' or 'free' dynamically allocated memory. Plus the above statement won't compile. Go figure.

And please see the date of the previous post before posting in a thread. This thread is 3 years old.

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You