I have a code and i must complete it, make b[i]==a[i].
Code:
#include <stdio.h>
#include <stdlib.h>
#define N 5
int a[N]={80,75,50,90,45};
int main(int argc, char **argv) {
int i;
int *b;
b=(int *)malloc(sizeof(int)*N);
if(b==NULL) {
fprintf(stderr,"malloc error\n");
exit(1);
}
for(i=0;i<N;i++) {
_________________
}
for(i=0;i<N;i++) {
printf("%d\n",b[i]);
}
free(b);
}
I must fill in the underline. And i think i must only write:
Code:
for(i=0;i<N;i++) {
b[i]=a[i];
}
Is that correct?
And when i try to find some example about malloc from internet, i have this code:
Code:
typedef struct data_type {
int age;
char name[20];
} data;
data *bob;
bob = (data*) malloc( sizeof(data) );
if( bob != NULL ) {
bob->age = 22;
strcpy( bob->name, "Robert" );
printf( "%s is %d years old\n", bob->name, bob->age );
}
free( bob );
I don't understand why they must write this sign "->"
Code:
bob->age = 22;
strcpy( bob->name, "Robert" );
thanks for your help.