#include<stdio.h>
int main()
{
int i;
string A[]={"Ahmet", "Mehmet", "Bulent", "Fuat"};
for(i=0;i<=3;i++){
printf("%s",A[i]);
}
return 0;
}
How can i see my array's elements as output?
Compiler says "'string' undeclared".
This way:
char *A[] = {"Ahmet", "Mehmet", "Bülent", "Fuat"};
A is an array of pointers to char.
In C, a string can only be represented, as an array of characters.So, to represent an array of strings you have to make array of (array of characters). In C++ we have a STL called, string and you can make an array of string and use it in the the way you have written(ofcourse with modifications to C specific stuff in your code).
you can use cs50 library to work with string or you can work with pointers.
CS50
string names[] = {"Mohammed", "Mhammed", "Ali", "Lora"};
pointer
char *names[] = {"Mohammed", "Mhammed", "Ali", "Lora"};
stringin C.üin"Bülent"may not show up as just onecharas you C compiler understands it.