Questions tagged [stdio]

This tag is for questions regarding "Standard I/O", i.e. I/O using the facilities in the C header or using the standard streams stdin, stdout, stderr.

The C standard header <stdio.h> defines facilities for using data streams via FILE objects and also declares the pre-defined standard streams, stdin, stdout and stderr.

The standard IO streams can be used from C in two ways:

  1. Using standard IO streams as implemented by the standard header <stdio.h> e.g. fprintf (stdout, "hello, world\n");
  2. Using the underlying file descriptors directly using the facilities in <unistd.h> e.g. write (STDOUT_FILENO, "hello, world\n", 13);. Note that this is not ISO C, but POSIX.
1090 questions
8
votes
1 answer

No output when using `fprintf' after `fwprintf'

This just happened to me while testing a part of a bigger program that I isolated. The original function would remove non ascii characters from a string in a special manner that I needed, the thing is this program #include #include…
Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
8
votes
2 answers

'printf': identifier not found

I have included stdio.h into my C++ project, why am I still getting this error? Also, after I added #include , printf(), in my code, was no longer underlined in red to suggest that there was any error. Also, I would like to use the function,…
Raisintoe
  • 201
  • 1
  • 4
  • 11
8
votes
6 answers

PHP - detect STDIO input

What I want is being able to optionally pipe STDIO to a PHP script. If not, it'll take input from a file instead. So sometimes I'll simply run the script, other times I'll do something like grep text logfile | php parseLog.php I have a loop very…
Arkandel
  • 339
  • 2
  • 10
8
votes
3 answers

who free's setvbuf buffer?

So I've been digging into how the stdio portion of libc is implemented and I've come across another question. Looking at man setvbuf I see the following: When the first I/O operation occurs on a file, malloc(3) is called, and a buffer is…
Evan Teran
  • 87,561
  • 32
  • 179
  • 238
8
votes
4 answers

Concurrent/Non-blocking console keyboard input

I'm working on a MUD in java. I read player input every tick, but I'm using Scanner which uses blocking operations. I want to have non-blocking input. I've looked at the nio package which has a Selector class, but I'm not sure how to use it with…
Robert Qualls
  • 81
  • 1
  • 2
7
votes
1 answer

Is it possible to output on multiple terminal windows within a single C program?

Basically what I'd like to do is have two output terminal windows for a single program. One would be displaying a log of actions being taken by the program, and the second would be displaying something like a table of values. All of the output for…
7
votes
1 answer

unresolved external symbol __stdio_common_vswprintf

I'm compiling a kernel mode driver that uses the Microsoft Dmf framework (DmfK.lib) After the last Visual Studio update some strange linker errors appeared : EmulationTargetPDO.obj : error LNK2019: unresolved external symbol __stdio_common_vswprintf…
SamT
  • 528
  • 4
  • 14
7
votes
1 answer

Can getline() be used multiple times within a loop? - Cython, file reading

I want to read a file, 4 lines by 4 (it's a fastq file, with DNA sequences). When I read the file one line by one or two by two, there's no issues, but when I read 3 or 4 lines at once, my code crashes (kernel appeared to have died on jupyter…
Sylvain
  • 679
  • 9
  • 13
7
votes
2 answers

std::getline alternative when input line endings are mixed

I'm trying to read in lines from a std::istream but the input may contain '\r' and/or '\n', so std::getline is no use. Sorry to shout but this seems to need emphasis... The input may contain either newline type or both. Is there a standard way to do…
spraff
  • 32,570
  • 22
  • 121
  • 229
7
votes
5 answers

C without stdio, what is possible?

I've been interested in programming an operating system for some time. Delving through a few different sites, I've come across an interesting concept (to paraphrase): if you start writing your bootloader with #include, you've already made a fatal…
Matticus
  • 155
  • 2
  • 10
7
votes
2 answers

fgets(), signals (EINTR) and input data integrity

fgets() was intended for reading some string until EOF or \n occurred. It is very handy for reading text config files, for example, but there are some problems. First, it may return EINTR in case of signal delivery, so it should be wrapped with loop…
firk
  • 339
  • 2
  • 10
7
votes
1 answer

Why doesn't `putStrLn getLine` work?

I'm complete newbie on Haskell. My Haskell script with GHCi, Prelude> let a = putStrLn getLine makes an error like this. :1:17: Couldn't match expected type `String' against inferred type `IO String' In the first…
eonil
  • 83,476
  • 81
  • 317
  • 516
7
votes
2 answers

C file pointer changing after fork and (failed) exec

I made program which make fork and I think child does not affect parent. But file pointer is changed although I did not made any changes in the parent. #include #include #include #include #include…
fnclovers
  • 119
  • 9
7
votes
1 answer

Does fwrite flush the buffer on '\n'?

I have my own implementation of _open(), _close(), _write(), _read(). My code: FILE *f = fopen("0:test", "wb"); // calls _open() fwrite("hello ", 6, 1, f); fwrite("world\r\n\0", 8, 1, f); // calls _write(3, "hello world\r\n", 13) fflush(f); …
Cosinus
  • 534
  • 4
  • 10
7
votes
2 answers

C- File input/output buffers and setvbuf()

In C language, does fopen() really creates two buffers, one for input and the other for output? This is what my C book says: Normally, the first step in using standard I/O is to use f open ( ) to open a file. (Recall, however, that the stdin,…
AlexQualcosa
  • 467
  • 6
  • 11