how to change single char in string array?
问题 Having this: #include <stdio.h> #include <stdlib.h> #include <ctype.h> char *up(char *); int main() { char initstr[20]; printf("enter string\n"); fgets(initstr, 20, stdin); char *str = up(initstr); printf("%s\n", str); } char *up(char *in) { char *ret; for (ret = in; *in != '\n'; *(ret++) = toupper(*(in++)) ); return ret; } Run it as: $./a.out enter string abc #only new line from `printf("%s\n",str);` From debugger Hardware watchpoint 3: in Old value = 0x7fffffffdc20 "abc\n" New value =