Hello I have a problem with my C code. I'm trying to let user assign a string to a previously defined char *srchstr
; and char *repstr;
. By looking at other similar threads I've tried implementing it in the following way but it still fails:
char *srchstr;
srchstr = malloc(256);
char *repstr;
repstr = malloc(256);
printf("what are you searching for?:");
scanf("%255s",&srchstr);
fflush(stdin);
printf("\n what do you want to replace it with?:");
scanf("%255s",&repstr);
The whole idea behind the program was to give user ability to chose what text he wants to replace with what (whole code works just fine with srchstr
and repstr
defined in code but i cannot implement user input)
this is how it looked like in the beggining:
char *srchstr = "400,300";
char *repstr = "400,300: (000,000,000) #000000";
How can I fix it so user can type in the srchstr
and repstr
?