c - how to replace a char in char * -
total newbie here. trying replace character in char * program gives error
#include <stdio.h> int main(int argc, char **argv) { char *mystring ="love alweys better yoe"; int count = 1; (count ; count < 23; count++) { if ((mystring[count] == 0x65 )) //&& ((mystring[count+1] > 0x41) && (mystring[count+1] < 0x7a))) { mystring[count] = 0x45; //here occur freezing printf ("%c\n", mystring[count]); //break; }; }; printf("%s\n",mystring); return 0; }
the
char *mystring ="love alweys better yoe"
makes mystring read-only
you need copy string buffer before can change it
e.g.
char mystring[128]; strcpy( mystring , "love alweys better yoe" );
Comments
Post a Comment