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

read and write from and into file

I'm trying to write a function which get numbers from the user and, put them in file and then reads them and find the minimun. this is the code I wrote but It doesn't work at all. can someone please help me understand what I'm doing wrong? I'm new…
Ofir Sasson
  • 673
  • 4
  • 16
  • 39
-1
votes
1 answer

Check if the next read will set EOF indicator

What's the best way to check if I've reached the end of a FILE* stream without manually keeping track of the current cursor position and file size? The implementation should work in read and read/write mode of fopen. I came up with this: int…
Andreas
  • 9,245
  • 9
  • 49
  • 97
-1
votes
1 answer

C: getc returns -1

The problem I have is in this line: int tok = getc(fp); getc returns -1. Why? Thanks in advance. #include #include #include "file_reader.h" /** * Opens a text file and reads the file. The text of the file is stored * in…
Yuehai
  • 1,165
  • 1
  • 10
  • 20
-1
votes
1 answer

Integrating freeRTOS to an existing project

I'am attempting to integrate freeRTOS to my application that run on AT32UC3A0512. I downloaded a freeRTOS project example for EVK1100 (it Supports the AT32UC3A) and try to include the kernel source files, so my application hierarchy looks like…
fedi
  • 368
  • 3
  • 7
  • 18
-1
votes
1 answer

Passing a non-empty string to snprintf causes an unrelated char* array to change addresses

I'm working on the exercises in K&R's book, and I've run into a weird bug while trying to extend 04-06 to allow for variables with string names. Truthfully, I've actually managed to fix the bug (pretty simple - explained below), but I'd like to know…
velocirabbit
  • 706
  • 7
  • 16
-1
votes
3 answers

signed number behaviour in C

I am working on some wave file sample extraction and I am stuck with my small part. I have 24 bit data being extracted from a sample, say AB0293 (MSB being 1). I am using a 32 bit int variable to store this. I am unable to understand how to do this.…
-1
votes
2 answers

Why does scanf reacts like this?

#include "stdafx.h" #include "stdlib.h" int _tmain(int argc, _TCHAR* argv[]) { char *dumb = (char*)malloc(50); scanf("%[^\n]s", dumb); printf("%s\n",dumb); scanf("%[^\n]s", dumb); printf("%s\n", dumb); return 0; } I need…
Ciomegu
  • 47
  • 5
-1
votes
3 answers

gets and puts to get and print a string

i'm trying to get and print a string with gets and puts but i get a segmentation fault error when i use them togheter. this is the code i'm trying to get this working. [i type the string "prova" to test it] int main() { char *s; gets(s); …
user3757339
  • 7
  • 1
  • 4
-1
votes
1 answer

How to get and display the density and occurrence of words in C Language?

I currently work on a text file where it has a fixed number of words. And all I want is to count the occurrence of a word in a text file and output its density. I have 266 words inside a text file and I want to output the count and density of words…
ajdeguzman
  • 1,223
  • 3
  • 16
  • 27
-1
votes
1 answer

issues: Filename extension for tmpnam(), rand() generation algorithm advance, & fgetc()'s stream expression

I had finished reading about stdio.h functions and need some small clarifications. Please take a minute to give short explanations for the following: 1) tmpnam() : It only gives us a string containing a unique file-name, but what to do about the…
Jugni
  • 255
  • 5
  • 12
-1
votes
1 answer

Program should give to a word special numerical value (but…)

There's a program I wrote in C, it works perfectly. When I tried to translate it into the language C# it was not compiling. The problem was that C# doesn't know the meaning of scanf ("%19s" , string1); like in C. I changed scanf to: string…
Gio
  • 81
  • 1
  • 2
  • 9
-1
votes
2 answers

Over-riding Standard Input and Output in C

I wrote this code for overriding the cat command in Ubuntu. The following three formats for cat instruction are working properly but rest are not working. Working ones: ./catf > File.txt ./catf < File.txt Not Working: ./catf File1.txt >…
Alfred
  • 1,543
  • 7
  • 33
  • 45
-1
votes
1 answer

Reading bytes from /dev/random fails

I have a piece of code written in POSIX compliant C and it doesn't seem to work correctly. The goal is to read from /dev/random, the interface to the Linux/BSD/Darwin kernel's random number generator and output the written byte to a file. I'm not…
SevenBits
  • 2,836
  • 1
  • 20
  • 33
-1
votes
1 answer

C header

I was trying to compile a 3-file C programme with 1 file cointaining tha main() , one containing headers related to a struct type I created and the third one the functions related to the struct. I was getting an error on the return temp; on a…
-2
votes
1 answer

Is it possible to use stdio buffer for this? If now, any alternatives (without implementing myself)?

(note: This question is for some schoolwork I'm doing. I don't need to know how to implement this, just need to know if it's possible and how can I learn more about it) I'd like to use a user level buffer for a file using only a file descriptor and…
brunoais
  • 6,258
  • 8
  • 39
  • 59