I would like to know if it is possible to store one string and one integer in a array ??
like i would like to store
"john" "45"
"darwin" "56"
"felicious" "20"
in an array. Is that possible ???
Printable View
I would like to know if it is possible to store one string and one integer in a array ??
like i would like to store
"john" "45"
"darwin" "56"
"felicious" "20"
in an array. Is that possible ???
Of course, a better way to maintain grouping would be to use a structure:Code:char *array[] = {
"john", "45",
"darwin", "56",
"felicious", "20"
};
Code:struct s {
char string[SIZE];
int integer;
};
struct s array[] = {
{ "john", 45 },
{ "darwin", 56 },
{ "felicious", 20 }
};
If i use the first option, when i wanted to print that time, woudlnt it be ..?
printf("%s", array[0]); // john
printf("%s", array[1]); // 45
printf("%s", array[2]); // darwin
printf("%s", array[3]); // 56
printf("%s", array[4]); // felicous
printf("%s", array[5]); // 20
>when i wanted to print that time, woudlnt it be ..?
Try it and see.
May i know whats wrong with this code ?? There isn't any error while compiling. But when i try to build the file that time, it display the following error
"Linking...
prac3a.obj : error LNK2001: unresolved external symbol _punctuationx
Debug/prac3a.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe."
Code:struct s {
char string[10];
int integer;
};
struct s reservedx[];
void hello()
{
for(i=0; i <= 8; i++)
{
reservedx[i].integer=0;
strcpy(reservedx[i].string,"hello");
}
}
i know whats wrong already. I didnt declare the size of the array.
Thanks anyway..