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
-2
votes
2 answers

Why does the terminal hang when reading from STDOUT?

So I've entered two lines of code into a Python shell to read from STDOUT and write to STDIN: >>> writetoinput=open("/dev/stdin","w") >>> readfromoutput=open("/dev/stdout") and unexpected things happen when you do file operations on them. First, I…
-2
votes
1 answer

What if I put 2 or more into 'size' parameter in fread()?

If I use: fread(&buffer, 16384, 1, file); // Read 16384 bytes once? instead of: fread(&buffer, 1, 16384, file); // Read a byte 16384 times? to read a plain text document file, would it succeed? Is it efficient?
-2
votes
2 answers

How to remove the final "%" sign from the output in c with printf()

I have the following code: #include int main(){ printf("hello world"); } The output is the following: hello world% Is there a way to remove the final "%" (which is actually black on white and not white on black like the other…
ecjb
  • 5,169
  • 12
  • 43
  • 79
-2
votes
3 answers

Having infinite loop because scanf() does not stop the program to take entry from user

I need to write a program which calculates fibonacci sequence but I stuck because of this infinite loop. When I enter -5 it prints Please enter "positive" term(s) number:. Then I enter "a" and it prints Please enter "numeric" term(s) number:…
Baran
  • 131
  • 8
-2
votes
1 answer

Broken files in C

I made a simple script to rewrite one file contents into another. Here's code: #include #include int main() { char filename[1024]; scanf("%s", &filename); // printf("Filename: '%s'\n", filename); int…
Зелди
  • 76
  • 1
  • 12
-2
votes
1 answer

How to write a c program that takes 2 strings as arguments from the command line?

I want to write a .c program using only libraries stdlib.h, stdio.h, and string.h. The program takes as input from the command line two words when the C program is is called - like this: .mycode WORD1 WORD2 where WORD1 and WORD2 are both series of…
prince12
  • 11
  • 4
-2
votes
1 answer

My code gives out Environment variables on Linux

Some of this code might not make any sense, (perhaps even I am perplexed) about how this happened and why? This code was intended for some other purpose, (i was trying to make a calculator, so the main source code [which had few problems] exists…
Sparsh_Mishra
  • 41
  • 1
  • 10
-2
votes
1 answer

C++ How can I redirect STDIN to a function

I've spent some time researching for a way to redirect STDOUT and STDIN to functions. While I eventually found and succeeded at redirecting STDOUT to a callback, I'm unable to redirect STDIN to a callback too (I can't find any resources except for…
Ricardo Antunes
  • 397
  • 2
  • 11
-2
votes
2 answers

Error in stdio.h file?

I'm trying to write and run "Hello World" in C. int main(int argc, char *argv[]) { #include puts("Hello world."); return 0; } However, I keep getting the following error in the Terminal: In file included from…
-2
votes
4 answers

Whatever input, the answer is 67 ,why?

#include #include int main() { int a; scanf("%*2s",&a); printf("%d\n",a); return 0; } Output: 1351 (input to scanf) 67 (output from printf) Whatever input I give,the answer is always 67. Where is the 67 coming…
JingYi
  • 67
  • 1
  • 3
-2
votes
3 answers

fastest way to write integer to file in C

I am doing a homework to programming in C. Bonus points are for quick writing to the file in there upload test system. I am trying to write a number of lines each comprising three space delimited decimal integer strings and then '\n' in file. The…
Stepan
  • 61
  • 1
  • 3
  • 12
-2
votes
2 answers

Having issues with C using float and printf

I'm trying to run some basic code in C to declare 2 float variables, and then divide them and put that value in the 3rd variable. After this I print all 3. #include int main () { /* variable definition: */ float a, b, c; /* variable…
-2
votes
2 answers

Find Quantity of Biggest integers in N integers in C

I want to do this code that tells you the number of (n) integers that are bigger (or equal) than a (k) input. So for example: input: 4 15 12 6 15 24 output: 2 So the 4 is the number of integers the user is going to input and the 15 is the k…
-2
votes
4 answers

Not able to get particluar sequence in C but am able to get it in Python

I am trying to get a very simple and basic logic up and running using the C language. The following code gets it right on python, but I am not able to get the same results using C. //Python Code a = 2 while True: a=a*2 print(a) With the…
-2
votes
1 answer

Search file and compare strings it contains with inputted variable

I'm trying to search a file containing information on a group of people, for example: their first name, last name and ID. I'm prompting the user to enter their ID code. The program should search the text file and ensure that their code matches the…