I am trying to take input from user and store it as a char array. I have the following code in which the function array, returns the address to the character array. However, I am getting a core dump error, what is happening here?
//reading and storing input from user as char array
int * array(int * r){
int ch;
int i;
r[10];
printf("enter your name: ");
for ( i = 0; i < 10; i++){
r[i] = getc(stdin);
printf("%c", r[i]);
}
return r;
}
//main
int main(void){
int *p;
p = array(p);
}
p, so you're dereferencing an uninitialized pointer.int.r[10];doesn't do anything. You also declare a variablechthat you never use at all.int *p;toint p[10];