How to read these mixture of data in C

This program reads from the file and converts the tokens to floats. You should read an entire line and tokenize it. Then you just need to create an array and add to the array at the right place in the code. #include <stdio.h> #include <stdlib.h> #include <memory.h> int main(void) { FILE *sp1; char line[256]; double … Read more

C program goes into infinite loop with scanf [duplicate]

Check return value of scanf and clear input buffer in case of illegal input. Like this: #include <stdio.h> #include <stdbool.h> int main(void) { float sales, commission, earnings; int state; while(true) { printf( “Enter sales in dollars ( -1 to end ): ” ); if((state = scanf(“%f”, &sales )) != 1){ if(state == EOF) return 0; … Read more

scanf() not taking input from console [closed]

In your code, please change scanf(“%f”,&a); scanf(“%c”,&op); scanf(“%f”,&b); scanf(“%f”,&r); to scanf(“%f”,&a); scanf(” %c”,&op); //notice here scanf(“%f”,&b); scanf(“%f”,&r); Without the leading space before %c, the \n stoted by previous ENTER key press after previous input, will be read and considered as valid input for %c format specifier. So, the second scanf() will not ask for seperate … Read more

decimal of numbers in c

The error is that %d in the format specifier of both scanf and printf represents decimal, so it expects an int (in the case of scanf, a pointer to int) Since you are declaring b and c as float, %d in the lines scanf(“%d”,&b); printf(“%d lbs is %d kgs.”,b,c); should be changed to %f respectively. … Read more

Hangman code in C

I would suggest providing functions for this code. The code is difficult to read and follow. Start with first creating a menu function, then get user input function; also do checks with-in the function that verify that the input if valid before it sends a character back. Then check to see if the guess is … Read more