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
-1
votes
3 answers

scanf and printf not printing right values

What is going on here? The code goes like: #include #include int main() { char name[15]; char name_[15]; char answ[1]; printf("What's your name?\n"); scanf("%s", name); strcpy(name_, name); …
healLV
  • 9
  • 3
-1
votes
2 answers

I cannot read in a number using getchar()

Programming noob here. I have an assignment where I have to read in a number using getchar() and perform some operations on it. The number can either be a positive or negative number. This is the segment of my code that takes in input. I can't find…
-1
votes
1 answer

Input a dynamic length array in C using scanf

I have to input an array of integers. The length of this array is determined at runtime when the user hits some sentinal key (likely I'll use return) EXAMPLE //input path to be analyzed int n = 0; while(scanf("%d",&input[n])==1){ //?? …
Nick Steeves
  • 3
  • 2
  • 4
-1
votes
1 answer

fprintf() function in C is not working properly

I wrote this code to input a number from a user and output it to a file .But its is not working ,after running the code the output.txt file is still empty. Please tell me where I have done wrong . I assure that I have created the output.txt file…
Tatan
  • 1
  • 2
-1
votes
3 answers

About binary modes in fopen

I already read the C++ Reference about fopen access modes, but I don't understand the difference between "a+b" and "ab+", or between "w+b" and "wb+".
-1
votes
2 answers

My C program prints -39 on a new line and I can't figure out why

I've been playing around and trying to experiment with C for my university class and I've found something that my program does even though I did not tell it to! My full code: #include int main(void) { int c; while ((c = getchar()) !=…
Kyriazis
  • 71
  • 6
-1
votes
1 answer

fwrite() writing all 1's to more significant bits if sign bit of any single byte is 1 (writing int)

for (struct part *p = first; p != NULL; p = p->next;) { fwrite(&(p->num), sizeof(int), 1, inventory); fwrite(&(p->qoh), sizeof(int), 1, inventory); fwrite(p->name, sizeof(char), strlen(p->name) + 1, inventory); } p is a pointer to a…
-1
votes
4 answers

Unable to Calculate Correct Average

C language, stdio.h library Sample code: float avg; avg = 3 / 2; printf("Average: %.2f", avg); From the code above I expect the following output: Average = 1.50 But instead I get: Average = 1.00 Why is this? And how do I get the correct output?
lefrost
  • 461
  • 5
  • 17
-1
votes
2 answers

Having Trouble Counting and Summing Integers from Text File

Sorry for being such a novice. For this question I used C language, and the libraries stdlio.h and stdlib.h. Question So a question is asking me to: Open a text file named 'numbers.txt' in read mode. This text file has 6 integers in it. Read the 6…
lefrost
  • 461
  • 5
  • 17
-1
votes
1 answer

C function to read binary file doesn't work if used by other function.?

I wrote this function to return an unsigned char * containing the data from any file(using rbread mode) it looks like this: uchar * get_file_data (char *f_name, luint *len) { // verify file struct stat sBuffer; int iRc; iRc =…
Otard95
  • 3
  • 4
-1
votes
1 answer

How to redesign #include in C

I am working on a project in C, in which I am thinking to cut short stdio.h header file and only keep the code which I need. How shall I do this? Plus I would like to know whether cutting it short will make any difference to the speed?
-1
votes
1 answer

Why does my program print the same statement twice?

I am creating a simple application to keep track how long I am working. A user enters the amount of minutes of work they are doing and the program will keep track of the total until termination. The issue is after the first time the program is run…
-1
votes
1 answer

Unhandled exception at 0x0F828F0E (ucrtbased.dll) in Hello World.exe: 0xC0000005: Access violation writing location 0x00000002

I am new in C++ and I've started to learn last night I need help with the following error: Unhandled exception at 0x0F828F0E (ucrtbased.dll) in Hello World.exe: 0xC0000005: Access violation writing location 0x00000002. My code so far: #include…
Anton Pascu
  • 19
  • 1
  • 2
-1
votes
2 answers

Why does scanf expect two numbers?

I want the program to get the user's height and weight then input that into the bmi formula then output the result. The height question works fine but when you enter a number into the weight question and press enter, it just makes a new line. Once…
David Vlcek
  • 21
  • 1
  • 6
-1
votes
3 answers

scanf is collecting the wrong input

#include int main(void) { double c; scanf("%f", &c); printf("%f", c); } This is an exerpt from a program I'm attempting to write, but I get the same issue with something this simple. when I run this, and enter "1.0",…
rawrdid
  • 3
  • 1