Code:
#include <stdio.h>
#include <stdlib.h>
struct Files{
char name[40];
int years;
int age;
};
void f_age(struct Files data, int num){
int i;
for(i=0; i<num; i++){
printf("Please type your age:\n");
scanf("%d", &data[i].age);
}
}
int main(void){
int i, number;
struct Files *data;
printf("Please type a number for the variable number:\n");
scanf("%d", &number);
data=(struct Files *)malloc(number*sizeof(struct Files));
f_age(data, number);
// for(i=0; i<number; i++){
// printf("Please type your age:\n");
// scanf("%d", &data[i].age);
// }
for(i=0; i<number; i++){
printf("Age[%d]: %d\n", i, data[i].age);
}
return 0;
}
output: vasileios@vasileios-desktop:~/desktop$ gcc askisi1.c
askisi1.c: In function ‘f_age’:
askisi1.c:17: error: subscripted value is neither array nor pointer
askisi1.c: In function ‘main’:
askisi1.c:32: error: incompatible type for argument 1 of ‘f_age’
askisi1.c:12: note: expected ‘struct Files’ but argument is of type ‘struct Files *’
I am not so good in structs...and...working with fuctions but i still try to learn...there are some errors when i call the f_age in main and also when i initialize the variables...if anyone khows what's wrong please tell me...thanks...