I want to know how to delete an array of varible which is already exists?
For example:
char *hello = "Billgates";
now hello varible of array is exists,
now i want to clear all the element of hello array or delete it hello varible?
I want to know how to delete an array of varible which is already exists?
For example:
char *hello = "Billgates";
now hello varible of array is exists,
now i want to clear all the element of hello array or delete it hello varible?
You cant...what hello represents is a pointer to an array of chars situated in const memory.....you cant alter that memory or resize it...only read it....Originally posted by Jonh
I want to know how to delete an array of varible which is already exists?
For example:
char *hello = "Billgates";
now hello varible of array is exists,
now i want to clear all the element of hello array or delete it hello varible?
I see,
How about to check if name[256] is exists or not,
I need something that cant be repeated twice or more using: char name[256];
if it do then it would crash or something.
You can, however, put an empty string in its place. C-style strings are terminated with zero, usually expressed as '\0'. If you set the first element (element 0) of the array to zero and then print (display) it, nothing will print.
hello[0] = '\0': // Set string length to zero by replacing the B at position zero with '\0'
hello[4] = '\0'; // Set string length to 4 by replacing the g at position 4 with '\0' now hello will print as Bill.
'\0' is often replaced with NULL, or you can use a numerical 0 (zero) but not an ASCII zero
hello[4] = '\0'; // OK Changes Billgates to Bill
hello[4] = NULL; // OK Changes Billgates to Bill
hello[4] = 0; // OK Changes Billgates to Bill
hello[4] = '0'; // OOPS! Changes Billgates to Bill0ates
You can also fill the entire array with zeros if it makes you feel better
Ahhh, your second question is a bit more "interesting" because there are probably some really cool (more advanced) ways of accomplishing whatever you're trying to do...
The simpilest way of dealing with a bunch of names it to make an "array of arrays" Which is actually a two-dimensional array... and you can have multi-dimension arrays.
char name[3][256] ; // Declares 3 each 256 character arrays (or a 2-dimensional 3 x 256 array)
Now...
name[0] can contain "BillGates"
name[1] can contain "LarryEllison"
name[2] can contain "SteveJobs"
The more advanced concepts that come to mind are "structures", "linked lists", "vectors", as well as memory allocation and reallocation... but don't think you have to understand all that stuff now... I just wanted to give you a clue about what I thought was "interesting".