How to delete part of an array?
In one tutorial I downloaded, it said use "delete [] arrayname", but when I attempted to compile, it said "delete function undefined" or something to that effect. So I tried this:
Code:
char myname[4] = "ash";
ash[1] = ""; //trying to delete the s
printf("%s", ash);
but when it printed, it printed "a*h" (in place of the asterick it had some other weird symbol that I have no idea how to reproduce here :) ) So I guess I'm just asking if someone can tell me how to delete a single element of a string array. (I assume it's the same for a non-string array too). Also I see that you can't put a space in that way either..., I tried ash[1] = " "; so it should print "a h", but instead it has that weird character again....
Thanks for any help, I promise that once I start to learn more of c i'll ask more complicated stupid questions :)
solution to deleting ,part of an array
the solution to the problem i figured out ,is as follows
/*Program ----> deleting a part of an array */
/*In this program we are going to delete 'd'
key idea --->make the adderess of 'd' point to the next , and the next to the next
From -----------> Ekarshi Mitra (Btech ------1Year----CSIT)
Date -----------> 1-01-2006
Time -----------> 11:45 P.M*/
Code:
#include <stdio.h>
#include <string.h>
int main ()/*void main() can also be used , depends unpon programmer*/
{
char name[]="under test";
int marker=2,count,string_length=strlen(name);
/*now suppose we remove 'd' from under test*/
for(count=marker;count<string_length;count++)
{
name[count]=(int)*&name[count+1];/*typecasting done here*/
/* can be compiled removing (int) */
}
printf(" ans = %s",name);
getchar();
return 0;
}
/*compiled and run under devc++ (IDE) */