I'm a beginner to C but I have this code running on xcode through gcc on terminal:
#include <stdio.h>
#include <string.h>
int main(){
char name[12] = "Roman Mirov";
printf("My name is %s\n", name);
name[8] = 'k';
printf("My name is %s\n", name);
char greeting[] = "hello";
printf("%s %s\n", greeting, name);
strcpy(greeting, "greetings, ");
printf("%s%s\n", greeting, name);
return 0;
}
And it outputs this:
My name is Roman Mirov
My name is Roman Mikov
hello Roman Mikov
Abort trap: 6
My question exactly is, why it generates error instead of showing the last line as output "greetings, Roman Mikov"?