I am writing my code chunk by chunk and trying to use pointer arithmetic in the process. My code calls a function and then is suppose to ask the user for 8 numbers. This then stores the numbers into the array using pointers. My problem is that I run into a segmentation fault. I believe the issue has to do with my pointer and the addresses. The chunk of code I think is causing this issue is scanf("%lf", *(coeff+1));. Is this the area that is throwing the fault and if so, what is the way to fix this?
#include <stdio.h>
void get_poly(double *coeff){
int p;
printf("Enter the eight coefficients: ");
for(p = 0; p < 7; p++){
scanf("%lf", *(coeff+1));
}
}
int main(void){
int i;
double coeff[7];
get_poly(coeff);
printf("output");
for(i = 0; i < 7; i++){
printf("%lf",coeff[i]);
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire