How can I add different types in a table? Firstly I have to create a function in order to add the food that I ate (char
), the calories (int
) and the hour that I ate it (float
) in a table with maximum size [100][4]
.
The only knowledge that I have and I can use for this project for my university is pointers and tables, NOT structures (which is the solution I was also thinking)
I've tried many things and the only thing that I did is to fill only the first column with the name of the food.
for (j=0;j<4;j++){
if (j==0){
printf ("Add your food:\n");
//char
scanf("%s",&table[n][j]);
}else if (j==1){
printf ("Add calories:\n");
//int
scanf("%d",&table[n][j]);
}else if (j==2){
printf ("Add the time you ate:\n");
//float
scanf("%.2f",&table[n][j]);
}else if (j==3){
printf ("Kati\n");
}
}
I expected my code to show all the data I filled but of course that doesn't work. So is there any solution to add different types in a table?