24 questions
3
votes
1
answer
86
views
ungetc after a fwrite, fseek and fwrite fails
After reading a draft of the c23 standard (n3220), I was trying to gain an understanding of ungetc by writing a simple example.
In This Example I:
fopen a file named file.txt for updating, either ...
0
votes
1
answer
128
views
Ungetc() Not Ungetting Character
My code is extremely simple, but I figure that's best to figure out what's going on in my program. For some reason, I can't seem to get ungetc() to work properly, nor can I figure out it's purpose. ...
3
votes
2
answers
217
views
Why does ungetc have a parameter to specify which character to push back?
In my current understanding, you're supposed to call ungetc when you want to "un-get" the most recent character that you got from the stream, sort of like reversing the effect of an ...
2
votes
1
answer
83
views
Error when mixing calls to fgetc, ungetc() and fputc() witht the same file
This code mix calls to putc() and ungetc() on the same file:
#include <stdio.h>
int main(int argc, char *argv[])
{
FILE *fp;
int c;
fp = fopen("filetest.txt", "r+&...
1
vote
2
answers
873
views
Pushing characters back to stdin in C
Say input stream (stdin) has "abc" on it. I want to push back, say, 3 '*' chars to stdin to get something like "***abc". I was trying to use ungetc() (I did ungetc('*', stdin)) for ...
0
votes
0
answers
37
views
why was my version of ungetch() and getch() wrong? [duplicate]
i'm searching for a long time on net. but no use. please help me.
/* getch and ungetch to handle EOF Character In all the ungetch and getch
* functions written so far, the buf is declared as char buf[...
0
votes
0
answers
226
views
Using ungetc() to get the length of stdin for allocate memory, is it possible?
Here is the logic what I am trying to do;
get input char with fgetc() in the variable named ch,
check if not ch is EOF or equal to '\n',
increase int variable named counter,
then put the variable ch ...
6
votes
1
answer
801
views
Why does ungetc fail on some characters?
ungetc() seems to fail on some characters. Here is a simple test program:
#include <stdio.h>
int main(void) {
int c;
printf("Type a letter and the enter key: ");
#define TRACE(x) ...
0
votes
1
answer
1k
views
Finding empty line using fscanf
I'm supposed to read some variables named from "A" to "Z" and then evaluate them. The values in variables are matrices. This is example input:
B=[5 2 4; 0 2 -1; 3 -5 -4]
E=[-6 -5 -8; -1 -1 -10; 10 0 -...
0
votes
1
answer
116
views
wrap ungetc() without puts() gets() and streams in general
I'm porting net-snmp to an embedded platform that only has limited access to the filesystem and I stumbled upon a big problem. There's a part of the core code that uses the ungetc() function, which I ...
-3
votes
4
answers
256
views
Why the input "abc!!!" but the output is not "abc+++"? [closed]
I researching about input/output file.Below code relate some functions such as: fgetc(),fgets(),fputs(). i don't know why it does not work exactly as i want.Thank you so much ! Below is my code:
#...
1
vote
2
answers
418
views
modify fflush() that guarantee calling ungetc() twice in a row in C
I'm a C beginner, I want to call ungetc() twice in a row although I know in regular C it is not permitted. Someone told me I can modify Fflush() to do this job, however I don't know how to do it.
...
0
votes
1
answer
349
views
Function like ungetc in php
is there a function in php which does something similar to ungetc C? I mean a function that puts a character back onto a stream?
0
votes
1
answer
204
views
fefo is not checking EOF during its last iteration in while loop?
I have a code which uses ungetc,and fefo function but i noticed that fefo is not checking for EOF below is my code
#include<stdio.h>
int main ()
{
FILE *fp;
int c;
char buffer [200];
...
3
votes
2
answers
3k
views
confusion regrading ungetc function
I am not understanding how this program works?
char c;
int i;
for(i=1;i<=5;i++)
{
scanf("%c",&c);
printf("%c",c);
ungetc(c,stdin);
}
The output of the program is- character ...
2
votes
2
answers
95
views
fscanf and switch not working
I'm trying to read this .txt file:
( 1 2 ( 3 4 ( 5
with this code:
#include <stdio.h>
int main() {
FILE* f = fopen("teste.txt", "r");
int i;
char j;
while (feof(f) == 0){
...
0
votes
2
answers
2k
views
Undoing the effects of ungetc() : "How" do fseek(),rewind() and fsetpos() do it?Is buffer refilled each time?
Huh!!How shall I put the whole thing in a clear question!!Let me try:
I know that the files opened using fopen() are buffered into memory.We use a buffer for efficiency and ease.During a read from ...
2
votes
2
answers
1k
views
IO::Handle to get and unget unicode characters
I think I've run into a problem with Unicode and IO::Handle. It's very likely I'm doing something wrong. I want to get and unget individual unicode characters (not bytes) from an IO::Handle. But I'm ...
0
votes
3
answers
952
views
understanding ungetc use in a simple getword
I've come across such an example of getword.
I understand all the checks and etc. but I have a problem with ungetc.
When the c does satisfy if ((!isalpha(c)) || c == EOF)and also doesn't satisfy ...
0
votes
1
answer
244
views
Equivalents for these functions in SolFS?
I am making an extension for an application. My extension uses SolFS and I want to use it to redirect all file traffic to SolFS. To accomplish this I need a bit of help because SolFS has not the ...
8
votes
4
answers
2k
views
ungetc: number of bytes of pushback
ungetc is only guaranteed to take one byte of pushback. On the other hand, I've tested it on Windows and Linux and it seems to work with two bytes.
Are there any platforms (e.g. any current Unix ...
3
votes
3
answers
2k
views
Is there a C++ version of ungetc?
Is there a C++ version of ungetc?
That is, can I put a character back onto an istream?
2
votes
6
answers
3k
views
ungetc in Python
Some file read (e.g. readlines()) functions in Python copy the file contents to memory (as a list).
I need to process a file that's too large to be copied in memory and as such need to use a file ...
2
votes
3
answers
2k
views
InputStreamReader.markSupported is false
I need to “un-read” characters from an InputStreamReader. For that purpose I wanted to use mark and reset but markSupported returns false for the InputStreamReader class, since it doesn’t maintain an ...