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

Segmentation fault, Idont know reason

I actually try to generate and fill random matrix and save it in plain text, txt, but have problems when I try to generate more than 1000 files than equivalent to 2000 files in working directory. I want understand the reason and the solution for…
William Trigos
  • 360
  • 1
  • 10
-2
votes
2 answers

How can we restrict user to enter characters and also integers greater than specified length in C?

I'm trying to create a C program on OTP (One Time Pad) encryption. The program takes a string to be encrypted from the user. Then it has to ask for the length of the key before taking the key (in integer). Since I want the program to be 100%…
Arlene Batada
  • 1,565
  • 2
  • 11
  • 11
-2
votes
6 answers

A simple "for" command doesnt work using only the stdio library

Using the same machine and IDE as reffered in my other question (third paragraph at Problems in code or my IDE/comp is bugged?) I try to run this code: #include #define n 3 int main() { int i; float values[n],sumval,svmean,tmp; …
John
  • 11
  • 3
-2
votes
2 answers

How to prevent Lua using stdio or redirect stdio in a rtos

I am trying to port Lua to ucos on a arm9 cpu. lua source code has usd stdio lib at many place. Yet, no uart is left for stdin/sdout ect in my hardware. More worse, the compile of ADS use the semihosting if stdio is used. So I wanto to avoid using…
vinge
  • 1
  • 1
-2
votes
3 answers

C Data Type Creation

So I'm trying to learn C and I understand that it doesn't have classes. However, I have only been doing c++ programming and to create an object of a special type, let's say car, I would have to make a class for it. Something like this: class Car { …
Richard
  • 5,840
  • 36
  • 123
  • 208
-3
votes
5 answers

output of c code

Why output is giving 3 , expecting -3. How to handle such preprocessing in c? #include #include #define sq(x) ((x<0)?sqrt(-x):sqrt(x)) int main() { int x; x=sq(-9); printf("%d\n",x); return 0; }
anil
  • 29
  • 6
-3
votes
1 answer

Problems with segmentation fault

I am using this code to print arguments that are less or equal to 100. The problem happens when i try to compile, it always give me the error Segmentation Fault althought I do not know why this is happening. Can anyone help me to understand what is…
-3
votes
3 answers

Is it possible to add my own functions to a C existing library?

Is it possible to add my own functions to a C existing library? For example, I want to add this function: #include int main() { int prices[5] = { 1, 2, 3, 4, 5 }; int size = sizeof prices / sizeof prices[0]; return size; } to…
Daniel
  • 5
  • 1
  • 6
-3
votes
3 answers

Different and odd results when using prefix and postfix operators in function arguments

Code: #include int main() { int i = 3; printf("%d %d %d %d %d\n",i = 7,--i,i = 18, i+5, i = 0); printf("%d %d %d %d %d\n",i = 7,i--,i = 18, i+5, i = 0); return 0; } Output: 7 7 7 5 7 7 18 7 5 7 Why I am getting this…
-3
votes
1 answer

Git Bash "fatal error: stdio.h: No such file or directory"

I just finished installing GCC on my windows laptop with MinGW, stdio.h library is there somewhere inside the file but Git Bash and windows CMD do not recognize it. I tried to run a simple Hello World program and it compiles but cannot find stdio.h…
Isa Neves
  • 1
  • 1
-3
votes
2 answers

C "stdio.h" function alias/rename

I'm trying to rename a "stdio.h" function or at least make an alias for it. I tried: #include #define printf() test() int main() { teste("Hello World!\n"); return 0; } but without success, I've also tried to download the stdio.h…
User
  • 141
  • 1
  • 9
-3
votes
2 answers

How do i change char to number?

i need to change some character into numbers for example: I = 1 R = 2 E = 3 A = 4 S = 5 G = 6 T = 7 B = 8 P = 9 O = 0 input example: HELLO IM GOOD output example: H3LL0 1M G00D
-3
votes
1 answer

Why the char arguments in scanf(%s) cannot be displayed in %c even disordered?

char num1, num2; scanf("%s %s", &num1, &num2); printf("num1=%c, num2=%c", num1, num2); I executed above code on Visual Studio in Mac with following cases: Input: a b => num1=, num2=b Input: ab c => num1=, num2=c Input: a bc => num1=c,…
skyline
  • 443
  • 9
  • 31
-3
votes
1 answer

C: Simple CSV reader/writer - infinite loop behavior

My program will compile, but when I run the exe, there is no output and the program does not terminate. I've tried to find the line of code that might be causing the problem by printing "flags;" however, none of my flags are printed, even the flag…
-3
votes
2 answers

Print out 2 digit numbers using only one integer and putchar

I have to print out 2 digit numbers (00, 01, 02, 03,... ,10, 11,..99) i.e. from 00 to 99 using only one integer and function putchar(). In ASCII table, these are signs from 0x30 (0) to 0x39(9). Also i may only use stdio.h library. Output…
Totenkoph93
  • 43
  • 1
  • 9