Here's what I want to do: If I have an integer followed by a specific string I want it to not be pushed on to a stack, otherwise I want it to be pushed on the stack. The problem is, when I test the next thing after the integer with fscanf, it "eats" the next thing, and essentially ruins my code. for example:
if(fscanf(read,"%d", &d)) { //If next is not the string "dont", then push but dont "eat" dont! push(d, write); }
Use ungetc()
#include <stdio.h>
int ungetc(int c, FILE *stream);
This will allow you to put back one char
char ch;
fscanf(read,"%d%c", &d, &ch);
if (WantToPutChBack(ch)) {
ungetc(ch, read);
}
You can only put back one char
before "getting" again, hope this is enough.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.