Hi everybody
I am a C newbie. A simplified version of my problem is below. The issue is that when the code is run, fgets is executed before any of the other code is run. I'm sure its some minor detail I am missing. Any help you can give in the matter would be appreciated.
Thanks in advance.
/* *************** *************** *************** ************* */
#include <stdio.h>
char line[100];
int height;
int width;
float area;
void go() {
fgets(line, sizeof(line), stdin);
sscanf(line, "%d %d", &width, &height);
}
int main() {
printf("Enter width height? ");
go();
area = (width * height)/2.0;
printf("The area is %f\n", area);
return(0);
}
I am a C newbie. A simplified version of my problem is below. The issue is that when the code is run, fgets is executed before any of the other code is run. I'm sure its some minor detail I am missing. Any help you can give in the matter would be appreciated.
Thanks in advance.
/* *************** *************** *************** ************* */
#include <stdio.h>
char line[100];
int height;
int width;
float area;
void go() {
fgets(line, sizeof(line), stdin);
sscanf(line, "%d %d", &width, &height);
}
int main() {
printf("Enter width height? ");
go();
area = (width * height)/2.0;
printf("The area is %f\n", area);
return(0);
}
Comment