.profile
#include <stdio.h> #include <stdlib.h> #include <string.h> /* Compile: cc -g -ansi -pedantic -Wall -O2 -o substitute-char substitute-char.c */ /* Run: ./substitute-char */ #define STRING "Hi World " int main(int argc, char *argv[]) { char *s; s = malloc(sizeof(char) * strlen(STRING)); /* Copy string. */ /* Tip: strdup() is non standard ANSI C, but easier to use than strncpy(). */ (void)strncpy(s, STRING, strlen(STRING)); printf("'%s'\n", s); *(s+2) = ','; *(s+9) = '!'; printf("'%s'\n", s); /* Always free() the result of a malloc(). */ free(s); return 0; }