string.h - How can I delete a string?

Hi Team,

I am a student.

I need delete a string, this need work in Linux.

We are using string.h but we do not have any coomand as "clear" or "erase",

Could you help me please?


Thanks!

Regards
Hello cnplusplus,

Since you did not provide any code I am guessing that this is a C program.

In that case you could try str[0] = '\0'; or use a for loop to set each element of the string to '\0'.

Andy
Hi Andy,

Yes, sorry, it's my first time here.

Is a C program.

I created a file, and some lines on this file, and need delete the file and the lines.


The file is a a virtual file, the lines are the strings for delete.

Thks!
Hello cnplusplus,

Looking into the "string.h" header file I found that you could use memset(str, '\0', sizeof str);.

Andy
Hello cnplusplus,

No worries.

It is always best to post the code that you have. Do not worry if it is wrong someone will have a suggestion to fix it up.

Since you are new:

PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.

Along with the proper indenting it makes it easier to read your code and also easier to respond to your post.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

Hint: You can edit your post, highlight your code and press the <> formatting button. This will not automatically indent your code. That part is up to you.

You can use the preview button at the bottom to see how it looks.

I found the second link to be the most help.


Without code it is just guess at what you are trying to do. And sometimes not easy to understand what you need.

Andy
the simplest way to delete a file is to borrow the operating system.
the easiest way to do this for a beginner is system:
system("rm filename");
which is the same as typing that string in a unix console. you can put a path on it etc just like in the console.

there are other ways that are safer (system is a security risk in professional software) but as you seem to be very new, we can save that for later.

Honestly not sure what you mean by virtual file ... are you using a virtual file system, or simulating a file in memory, or something else? The above assumes a virtual file system that works like a unix file system.... ?
Topic archived. No new replies allowed.