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

Fast way to check if file pointer points to a valid file

I am looking for fast (for performance-critical code), safe and cross-platform way to check if FILE* in fact points to a file upon successful previous call to fopen(). Asking for current position with ftell() is one approach, but I doubt that it is…
-3
votes
1 answer

A program that returns the letter that comes after and before

Im new to programming. The mission is to make a program that returns the pred and succ letter of a given letter as output data. The input data is any letter between b and z. I have declared every letter b-z as variables of themselves, and the input…
-3
votes
3 answers

Alternative to strcpy? or fix to strcpy in program?

I can't figure out what is wrong with this program. I have tried using strncpy(text,array[ ],sizeof(text)) already but that didn't solve anything. What I need is a simple method of copying string like in pascal language,…
otboss
  • 621
  • 1
  • 7
  • 16
-3
votes
3 answers

Why am I getting the error "Expression Syntax" while executing the following C code:

#include #define PRINT(a,b) (while(a
Gurmanjot Singh
  • 10,224
  • 2
  • 19
  • 43
-3
votes
19 answers

How to make the pyramid (CS50 Mario Program) formed by this code to be right aligned?

Please help me create the pyramid with height "n" print correctly using hashes and spaces that is right-aligned. I have posted the code itself below. The program correctly asks for the user input, but doesn't build the pyramid right-aligned. If…
SKammala
  • 33
  • 1
  • 1
  • 3
-3
votes
2 answers

Is it possible for an if statement to say if something is not entered?

I'm doing a project and I'm just curious to know if it is possible to have a line that says "if something is not entered" and a prompt statement would be followed. For example, if(id_ == NULL){printf("John Doe is absent.")}. Just a curious…
-3
votes
4 answers

Why does printf("%%") print only one percent (%) symbol?

When I run this following code: #include #include void main(){ clrscr(); printf("%%"); getch(); } I get % as an output? What might be the reason behind this logic?
-4
votes
1 answer

How would I get the last printf statement here to print both the output of x and y the user inputs?

(I am very new to C by btw) My current code #include char main() { char x; printf("Please enter your first initial:",x); scanf("%c",&x); char string[100]; char y; printf("Please enter your last name:",y); …
-4
votes
2 answers

What does the output which I get from printf("%d") mean?

I tried a code today and noticed that printf("%d") still have an output. On my computer I get a output of "1487504216". I would like to know why I gets a output and what the output means. The following is the code I have tried. #include…
龎逸傑
  • 7
  • 1
-4
votes
2 answers

Not able to read input from stdin/STDIN_FILENO in C?

I have this command line argument - cat file_name | ./a.out The problem is not reading from the cat command inside the C program as we can do that with read(), fgets(), fgetc() but the actual problem I am facing is after reading the data from cat…
-4
votes
1 answer

C Errors with FILE*

I have the following C code: #include #include "helper.h" int main(int argc, char ** argv){ if (argc < 4){ fprintf(stderr, "Usage: ./program_name \n"); exit(1); } FILE * target;…
everybody0523
  • 152
  • 1
  • 8
-4
votes
3 answers

Where did this value come from?

I am learning conversion specifier part of the C language. I know that %d works for printing value behind commas but, I don't understand why printf prints something when there are no values behind comma. There are also no compile errors. #include…
-4
votes
1 answer

What is wrong with this code, in special with file?

Implement an algorithm that reads a mathematical expression from the standard input and writes to Standard output if the expression is correctly bracketed. I made the code but I do not know if it's okay how I used the…
-4
votes
2 answers

passing stdio stream to another function c++

I have a function that opens and writes some stuff to a stdio FILE* stream. I then call another function that will build an xml that I want to then write to that same stream. Rather than passing that string xml back to the original function,…
Saif Ahsanullah
  • 204
  • 3
  • 13
-4
votes
1 answer

How C program load data from txt file?

I have found this code here on forum, it works fine but I have no clue how it works, why it work. Can someone tell me a few words about this code please? I would like to understant it and know how to use it. Or if you know some better way, how to…
Tehryn
  • 57
  • 1
  • 10
1 2 3
72
73