I have a file which will contains basic mathematical operations. An example:
1 + 23 / 42 * 23
I am scanning the file, putting each “element” into a struct and pushing it onto a stack I created. The problem I have is as follows:
char reading;
while(!feof(fp)) {
fscanf(fp, "%c", &reading);
....
This will scan 1, +, 2, 3 instead of 1, +, 23. What are other suggestions to use one fscanf and have it iterate and read all the inputs as intended to with respect to their type?
Regards,
You should use
fscanf()a bit different, like this:The size of
bufmust be something which could store the length of your numbers.