// Example of initializing C-style strings. // Example also illustrates output of strings. #include int main() { int i; char input[30]; char input2[30]; char greeting[6] = "Hello"; // leaving room for the null char char name[20] = "Marvin Dipwart"; // initializer string is smaller // than allocated space /* Now who really wants to count up the letters?? */ char str1[] = "The quick brown fox jumped over the lazy platypus"; /* Printing the strings. A couple ways */ printf("\ngreeting = "); for (i = 0; i < 5; i++) // not preferred printf("%c", greeting[i]); printf("\nname = %s\n", name); // much easier printf("str1 = %s\n", str1); printf("\nType an input string: "); scanf("%s", input); printf("\nType another input string: "); scanf("%s", input2); printf("\nThe input string you typed: %s\n", input); printf("\nThe another input string you typed: %s\n", input2); return 0; }