c - Changing the value of the original string using a pointer -
i attempting change value of original string changing pointer.
say have:
char **stringo = (char**) malloc (sizeof(char*)); *stringo = (char*) malloc (17); char stringone[17] = "a" ; char stringtwo[17] = "b"; char stringthree[17] = "c"; char newstr[17] = "d"; strcpy(*stringo, stringone); strcpy(*stringo, stringtwo); strcpy(*stringo, stringthree); //change stringone newstr using stringo?? how can change stringoneso same newstr using pointer stringo?
edit: guess question rather unclear. want modify latest string *strcpy copied from. if strcpy(*stringo, stringthree); last called, modify stringthree, strcpy(*stringo, stringtwo); string two etc.
i want modify latest string
strcpycopied from. ifstrcpy( ( *stringo ), stringthree );last called, modifystringthree,strcpy( (*stringo ), stringtwo );stringtwoetc.
it not possible approach since making copy of string using strcpy -- not pointing blocks of memory. achieve goal following:
char *stringo = null; char stringone[ 17 ] = "a"; char stringtwo[ 17 ] = "b"; char stringthree[ 17 ] = "c"; char newstr[ 17 ] = "d"; stringo = stringone; // points block of memory stringone stored. stringo = stringtwo; // points block of memory stringtwo stored. stringo = stringthree; // points block of memory stringthree stored. strcpy( stringo, newstr ); // mutates stringone same string newstr. ... note mutating (updating) stringo points to, not copying string it. allow mutate values in blocks of memory stringo points (which consequently latest stringxxx stored) -- requested.
Comments
Post a Comment