avar avar - 1 year ago 107
C Question

how to replace a char in char *

total newbie here.
i was trying to replace a character in char * but my program gives error

#include <stdio.h>

int main(int argc, char **argv)
char *mystring ="love is alweys better yoe";
int count = 1;

for (count ; count < 23; count++)
if ((mystring[count] == 0x65 )) //&& ((mystring[count+1] > 0x41) && (mystring[count+1] < 0x7A)))
mystring[count] = 0x45; //here occur the freezing
printf ("%c\n", mystring[count]);

return 0;

Answer Source


char *mystring ="love is alweys better yoe"

makes mystring read-only

you need to copy the string into a buffer before you can change it


char mystring[128];
strcpy( mystring , "love is alweys better yoe" );
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download