I declared four string variables and initialized in four different ways. I then used the printf function four times, as the name implies, to print to the console the four string variables.
I already tried printing one at a time, but that didn't worked out. After the first attempt, I tried using the escape sequence but that didn't work. I then tried searching online of finding the proper ways to print out string, but all I've found came back to same using the printf function.
#include <stdio.h>
int main() {
char name1[] = "Ignacio";
char name2[8] = "Ignacio";
char name3[] = {'D', 'i', 'e', 'g', 'o'};
char name4[5] = {'D', 'i', 'e', 'g', 'o'};
printf("Name: %s\n", name1);
printf("Name: %s\n", name2);
printf("Name: %s\n", name3);
printf("Name: %s\n", name4);
return 0;
}
EXPECTED OUTPUT:
Name: Ignacio
Name: Ignacio
Name: Diego
Name: Diego
ACTUAL OUTPUT:
Name: Ignacio
Name: Ignacio
Name: DiegoIgnacio
Name: DiegoDiegoIgnacio