Basically, the structure is public, however when I try to store information in it in one function and then use it in a diferent function, it just gives 0. Any suggestions would be greatly appreciated. Here is the structure and the two functions that I want to use it:
If you're asking for technical help, please be sure to include all your system info, including operating system, model number, and any other specifics related to the problem. Also please exercise your best judgment when posting in the forums--revealing personal information such as your e-mail address, telephone number, and address is not recommended.
I am writing a program in c and I have a problem with a structure
struct equation {
int maxpower;
float numerators[128];
};
struct equation EQN;
void enter_filename(void)
{
printf("Please enter the name of the file:");
gets(filename);
}
int readEquation(struct equation EQN)
{
FILE *equationfile;
int count;
/* Opening the file and printing ERROR! if it has not opened properly */
equationfile=fopen(filename, "r");
if (equationfile==0) {
printf("Error! File failed to open\n");
}
/* Reading in the integer value for the maximum power */
fscanf(equationfile, "%i", &EQN);
printf("Max power is %i\n", EQN.maxpower);
/*Reading in the numerator values and storing them in the array numerators[] */
for(count=0; count<(EQN.maxpower+1); count++) {
fscanf(equationfile, "%f", &EQN.numerators[count]);
printf("The numerators are %f\n", EQN.numerators[count]);
}
if (fclose(equationfile)==-1) {
printf("File failed to close\n");
}
return 0;
}
void display_polynomial(void)
{
char numstring[20];
int count;
printf("\nThe Equation = ");
for(count=0; count<(EQN.maxpower+1); count++) {
sprintf(numstring, "%G", EQN.numerators[count]);
if(count!=EQN.maxpower) {
printf("%sx^%i + ", numstring, (EQN.maxpower-count));
} else {
printf("%s\n", numstring);
}
}
}