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
11
votes
4 answers

Arduino: printf/fprintf prints question mark instead of float

I have the following code for an Arduino sketch: #include LiquidCrystal lcd(12, 11, 5, 4, 3, 2); static FILE lcdout = {0} ; static int lcd_putchar(char ch, FILE* stream) { lcd.write(ch) ; return (0) ; } void setup() { …
Nicu Surdu
  • 8,172
  • 9
  • 68
  • 108
11
votes
6 answers

Getting another program's output as input on the fly

I've two programs I'm using in this way: $ c_program | python_program.py c_program prints something using printf() and python_program.py reads using sys.stdin.readline() I'd like to make the python_program.py process c_program's output as it…
Andrea Ambu
  • 38,188
  • 14
  • 54
  • 77
10
votes
1 answer

Using fopen() in Objective-C

I am puzzled by a crash I keep getting due to an error at this section of code: FILE *fid200; fid200 = fopen ( "Length200Vector.txt" , "w" ); if (fid200 == NULL) perror("Error…
Kevin_TA
  • 4,575
  • 13
  • 48
  • 77
10
votes
2 answers

stdin seems much slower than stdout (python). Why?

I have two python programs (one is a subprocess) that need to communicate with each other. Currently I am doing that through stdin and stdout. However, writing to the subprocess's stdin seems painfully slow. a.py, a program that takes an arbitrary…
Conley Owens
  • 8,691
  • 5
  • 30
  • 43
10
votes
2 answers

PyInstaller unbuffered stdio

Problem Docker image sizes should commonly be as small as possible. Using full-blown environments like a standard python image results often, with all dependencies installed, in heavily bloated images. Packaging python into stand-alone executables…
p-j-e
  • 236
  • 1
  • 7
10
votes
2 answers

How to determine number of characters that were read with fgets()?

This is the description of fgets() from the man page: char *fgets(char *s, int size, FILE *stream); ... RETURN VALUE fgets() returns s on success, and NULL on error or when end of file occurs while no characters have been read. It doesn't…
James Ko
  • 32,215
  • 30
  • 128
  • 239
10
votes
2 answers

Elixir/Erlang: How to find the source of high CPU usage?

My Elixir app is using about 50% of the CPU, but it really should only be using <1%. I'm trying to figure out what is causing the high CPU usage and I'm having some trouble. In a remote console, I tried Listing all processes with…
Jesse Shieh
  • 4,660
  • 5
  • 34
  • 49
10
votes
1 answer

Check whether the process is being run as a pipe

I have a small Python utility which should be run only as a pipe. I want it to print out the help message when it runs stand alone. How can a process know whether it is being used as a pipe. Comparing sys.stdin and sys.__stdin__ does not work.
jackhab
  • 17,128
  • 37
  • 99
  • 136
10
votes
2 answers

fread Only first 5 bytes of .PNG file

I've made a simple resource packer for packing the resources for my game into one file. Everything was going fine until I began writing the unpacker. I noticed the .txt file - 26 bytes - that I had packed, came out of the resource file fine, without…
Sam Blackburn
  • 288
  • 2
  • 9
10
votes
3 answers

CreateProcess with new console window, but override some std i/o handles

If you use CreateProcess with the flag CREATE_NEW_CONSOLE, the new process has its standard input, output, and error handles directed to the new console window. If you want to override the I/O streams, you can do so by setting the handles in…
Adrian McCarthy
  • 45,555
  • 16
  • 123
  • 175
10
votes
2 answers

mingw: function not found when compiled with -std=c++11

I was trying to compile the code below (from https://stackoverflow.com/a/478960/683218). The compile went OK, if I compile with $ g++ test.cpp but went wrong when the -std=c++11 switch is used: $ g++ -std=c++11 test.cpp test.cpp: In function…
thor
  • 21,418
  • 31
  • 87
  • 173
10
votes
3 answers

printf not printing to screen

If I try to run the following simple code under Cygwin on Windows 7, #include int main() { int i1, i2, sums; printf( "Enter first integer\n" ); scanf( "%d", &i1 ); printf( "Enter second integer\n" ); scanf( "%d", &i2 ); sums = i1 +…
user1060986
  • 141
  • 1
  • 1
  • 3
10
votes
3 answers

Where can I find the implementation of stdio.h in Visual Studio?

I could find stdio.h header file easily through search in Windows Explorer, but couldn't find its implementation file like stdio.lib(?). Where can I find it? Additionally, I can't find Windows.h through search in Windows Explorer, although I can…
David Johns
  • 1,201
  • 5
  • 15
  • 34
10
votes
2 answers

Does stdio always set errno?

When a stdio stream encounters an error (but not EOF), the stream's error indicator will be set so that ferror() will return nonzero. I have always assumed that more information is available in errno. But how do I know this? Documentation for some…
Adrian Ratnapala
  • 5,485
  • 2
  • 29
  • 39
9
votes
1 answer

How can I trap a signal (`SIGPIPE`) for a socket that closes?

I've written a server that accepts a socket connection on a secondary port for the purposes of streaming debugging information that normally goes to stderr. This second port --an error serving port-- is only intended to have one connection at a…
Jamie
  • 7,075
  • 12
  • 56
  • 86