hello! I have been having difficulty with printing an array in my homework assignment and I have been able to find a solution online. Could you guys help me?
I am using a C++ programming system! I have tried using the printf("%s"); to print it, an I have also attempted for loops, but to no avail.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() // missing type int
{
char state[4][10]; // You have 4 elements here
char str1[]="Florida";
char str2[]="Oregon";
char str3[]="California";
char str4[]="Georgia";
strcpy(state[0],str1); // strcpy (destination,source);
strcpy(state[1],str2); // You had it backwards
strcpy(state[2],str3);
strcpy(state[3],str4);
printf("%s", state[0]); // use printf("%s", "A String"); to print a string
printf("%s", state[1]);
printf("%s", state[2]);
printf("%s", state[3]);
return 0;
}