Trying to figure out how to read in multiple variables through a file. for example i know how to read in one, if i have a file called “datainput” which has the line of text “150” and then in my program if I have int value; and then scanf(“%d”, &value); when i run the program with the file it reads the file and then applies it to my variable. but what I am trying to do now is something similar but instead read in 2 values, so say in my text file i will have “3.1, 3.4” something like this and then put it on variable 1 and 2 something like that. anyone have any ideas?
Share
To read in two values all you have to do is add an additional format specifier to the
scanf()call:Also, just to note if you are reading from a file you need to use the function
fscanfhas a similar format toscanfexcept that you need pass a pointer to the file you are working with: