Hello people.
I'm getting problems with fgets.
Code:
while (run) {
printMenu();
scanf("%d*c", &opt);
switch (opt) {
case 1:
printf("Create a new component\n");
do {
printf("Serial number?\n");
scanf("%s*c", c_serial_number);
validStringSize = verifyStrLengh(c_serial_number, STR_SERIAL);
} while ((indexof(c, n_elems, c_serial_number) != -1)
|| (validStringSize != -1));
do {
printf("Components' name\n");
fflush(stdin);
scanf("%s*c", c_name);
validStringSize = verifyStrLengh(c_name, STR_NAME);
} while (validStringSize != -1);
do {
//fflush(stdin);
printf("Components description\n");
//fflush(stdin);
fgets(c_description, STR_DESCRIPTION, stdin);
// strip_newline( c_description, STR_DESCRIPTION );
//scanf("%s*c",c_description);
// scanf("%*c");
validStringSize
= verifyStrLengh(c_description, STR_DESCRIPTION);
} while (validStringSize != -1);
do {//fflush(stdin);
printf("Price\n");
fflush(stdin);
validValue = scanf("%f", &price);
// scanf("%*c");
if (validValue == 0) {
printf(
"You inserted a invalid character, use numbers please\n");
}
if ((validValue == 1) && (price <= 0)) {
printf("Insert a positive value to price, please\n");
}
} while ((validValue != 1) || (price <= 0));
if (insertComponent(c, &n_elems, c_serial_number, price, c_name,
c_description)) {
printf("Component successfully inserted\n");
} else {
printErrorMessage("Insertion unsuccessful\n");
}
// scanf("%*c");
break;
I'm trying read from stdin with fgets. Without sucess.
Or "component's description" jumps withou get the value or get the value and enters on price infite cycle.
strip_new line is a function that I read in "web" it works. (but It don't work)
I need help, I've got to deliverd this "job" soon