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
9
votes
1 answer

Get running process' stdin/stdout with node.js

I am starting a process from node with child_process.spawn and handling process.stdout/stderr data events, and writing to stdin. Now, my node application may crash or get stopped, when it is restarted I find the process by it's PID, and then I would…
Gipsy King
  • 1,549
  • 9
  • 15
9
votes
3 answers

Can I stop std::cout flushing on "\n"?

According to to this post std::cout will automatically flush on \n when it is attached to an interactive device (e.g. a terminal window). Otherwise (e.g. when being piped to a file) it will act fully buffered and will only flush on .flush() or…
pauldoo
  • 18,087
  • 20
  • 94
  • 116
9
votes
1 answer

C - multiple warnings "pointer is missing a nullability type specifier" when compiling program, what do I do?

I recently started having problems with compiling C programs, getting 10, 20 or 100 warnings from the different C packages like stdio.h or stdlib.h. The warnings differ somewhat but usually say something like this:…
bjorkpalm
  • 93
  • 1
  • 6
9
votes
1 answer

Creating a new file avoiding race conditions

I need to develop a C++ routine performing this apparently trivial task: create a file only if it does not exist, else do nothing/raise error. As I need to avoid race conditions, I want to use the "ask forgiveness not permission" principle (i.e.…
Alberto M
  • 1,057
  • 8
  • 24
9
votes
1 answer

Behavior of fputc() for a stream opened with read mode

I am unable to find any reference to the specified behavior of fputc() when the stream was created with fopen("/some/path", "r"). I've searched the C11 Draft n1570 pdf looking for any reference with no luck, the fopen() function specification talks…
Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
9
votes
2 answers

freopen: reverting back to original stream

I needed to forward stdout to different files to separate some prints produced and the reverting back to normal stdout. I used freopen to switch to the file in this way: char name[80]; memset(name, 0, 80); strcpy(name,…
Jack
  • 131,802
  • 30
  • 241
  • 343
9
votes
2 answers

Reattaching to spawned process via nodejs

I am creating a small proprietary game server manager in Node.js; currently it runs the game by spawning via child_process: var server = spawn(cmd, args, { cwd: 'something' }); So long as the manager continues to run I can pipe commands and deal…
Chad
  • 19,219
  • 4
  • 50
  • 73
9
votes
7 answers

Tried and true simple file copying code in C?

This looks like a simple question, but I didn't find anything similar here. Since there is no file copy function in C, we have to implement file copying ourselves, but I don't like reinventing the wheel even for trivial stuff like that, so I'd like…
Eugene Bujak
  • 1,591
  • 2
  • 14
  • 14
8
votes
3 answers

Python: fork, pipe and exec

I want to execute a program in a python application, it will run in the background but eventually come to the foreground. A GUI is used to interact with it. But controls are offered via a console on stdin and stdout. I want to be able to control it…
Aki
  • 329
  • 3
  • 13
  • 28
8
votes
1 answer

How to write unit-tests for interactive console app

I have a console app, (written as a Symfony2 command) that is reading input from user via STDIN and with help of readline, user input is then passed to eval() The whole thing is just for having "debug shell" (something like a php -a) but within…
canni
  • 5,737
  • 9
  • 46
  • 68
8
votes
4 answers

C++ Input Performance

I was trying to solve a problem on InterviewStreet. After some time I determine that I was actually spending the bulk of my time reading the input. This particular question had a lot of input, so that makes some amount of sense. What doesn't make…
Winston Ewert
  • 44,070
  • 10
  • 68
  • 83
8
votes
3 answers

How to use exit() safely from any thread

According to the man page (2) the exit function is not thread safe : MT-Unsafe race:exit, this is because this function tries to clean up resources (flush data to the disk, close file descriptors, etc...) by calling callbacks registered using…
ShellCode
  • 1,072
  • 8
  • 17
8
votes
13 answers

What is a good programming pattern for handling return values from stdio file writing functions

I'm working on some code that generates a lot of ignoring return value of ‘size_t fwrite(const void*, size_t, size_t, FILE*)’, declared with attribute warn_unused_result warnings when compiled with g++, and I'm wondering about the best programming…
David Dean
  • 7,435
  • 6
  • 33
  • 41
8
votes
1 answer

Clang stdio,h file not found

I installed clang with Visual Studio and then built the highlighted project as it's said in the documentation. The build was successful, however when I try this: clang -cc1 -analyze -analyzer-checker=core.DivideZero test.c It says: test.c:1:10:…
UnguruBulan
  • 890
  • 4
  • 12
  • 24
8
votes
2 answers

write 2d array to a file in C

I used to use the code below to Write an 1D array to a File: FILE *fp; float floatValue[5] = { 1.1F, 2.2F, 3.3F, 4.4F, 5.5F }; int i; if((fp=fopen("test", "wb"))==NULL) { printf("Cannot open file.\n"); } if(fwrite(floatValue, sizeof(float), 5,…
Bobj-C
  • 5,276
  • 9
  • 47
  • 83