Using redirection sends the contents of the input file to stdin, so you need to read from stdin inside your code, so something like (error checking omitted for clarity)
#include <stdio.h> #define BUFFERSIZE 100 int main (int argc, char *argv[]) { char buffer[BUFFERSIZE]; fgets(buffer, BUFFERSIZE , stdin); printf("Read: %s", buffer); return 0; }
Related Posts:
- What is EOF in the C programming language?
- Why use conio.h?
- What is EOF in the C programming language?
- How to read groups of integers from a file, line by line in C++
- Reading in from System.in – Java
- Check if input is integer type in C
- C++ – pointer being freed was not allocated error
- Frontend Category Checkbox
- Input with pattern not working
- Implementing Taylor Series for sine and cosine in C
- pthread_join() and pthread_exit()
- Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’
- strdup() – what does it do in C?
- Why should we typedef a struct so often in C?
- dereferencing pointer to incomplete type
- Get a substring of a char* [duplicate]
- What does \0 stand for?
- Expression must be a modifiable L-value
- Why unsigned int 0xFFFFFFFF is equal to int -1?
- What is the significance of return 0 in C and C++?
- How do I use valgrind to find memory leaks?
- PHP “php://input” vs $_POST
- “error: assignment to expression with array type error” when I assign a struct field (C)
- How do you make an array of structs in C?
- Fastest JSON reader/writer for C++
- What is the difference between const int*, const int * const, and int const *?
- How to create my own header file in c++?
- Why am I getting InputMismatchException?
- Is there a function to copy an array in C/C++?
- C error: Expected expression before int
- Returning string from C function
- Fatal error: iostream: No such file or directory in compiling C program using GCC
- C – The %x format specifier
- What does it mean to write to stdout in C?
- what is the unsigned datatype?
- Examples of good gotos in C or C++
- Reading a string with scanf
- getopt_long() — proper way to use it?
- C read file line by line
- C read file line by line
- Copying a part of a string (substring) in C
- Incompatible implicit declaration of built-in function ‘malloc’
- gdb: “No symbol table is loaded”
- Need more information about Aborted (core dumped)
- Going through a text file line by line in C
- How to use glOrtho() in OpenGL?
- Reversing a string in C
- When a number is written as 0x00… what does the x mean
- How to remove the character at a given index from a string in C?
- waitpid, wnohang, wuntraced. How do I use these
- Convert C program into assembly code
- C: error: expected ‘)’ before ‘;’ token
- Returning an array using C
- Debug vs Release in CMake
- What are 0x01 and 0x80 representative of in C bitwise operations?
- Convert char array to string use C
- How to make parent wait for all child processes to finish?
- Use of cudamalloc(). Why the double pointer?
- OpenGL — GL_LINE_LOOP —
- Valgrind complains with “Invalid write of size 8”
- How to print an unsigned char in C?
- Read and write to binary files in C?
- Expression must be a pointer to a complete object type using simple pointer arithmetic
- Difference between sizeof(char) and sizeof(char *)
- How to empty a char array?
- Undefined reference to main – collect2: ld returned 1 exit status
- What does ** mean in C?
- Is there a way to have printf() properly print out an array (of floats, say)?
- How do you allow spaces to be entered using scanf?
- How can I do GUI programming in C?
- Preventing console window from closing on Visual Studio C/C++ Console application
- Structure padding and packing
- Allocating char array using malloc
- Implementation of strtok() function
- C fopen vs open
- switch case: error: case label does not reduce to an integer constant
- warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
- warning: return makes pointer from integer without a cast but returns integer as desired
- Dynamic vs static array in c
- Suggestions needed: Effective Java to C source code converter
- CSS/HTML: Create a glowing border around an Input Field
- The difference between char * and char[] [duplicate]
- In C, what exactly happens when you pass a NULL pointer to strcmp()?
- Linker error: “linker input file unused because linking not done”, undefined reference to a function in that file
- Constructor for structs in C
- Implicit function declarations in C
- Convert long long to string in C?
- How to empty input field with jQuery
- How to compile C program on command line using MinGW?
- Parsing command-line arguments in C
- The tilde operator in C
- How to use shared memory with Linux in C
- Add extra field to users
- Add description text under input field for new profile fields
- using checked function to verify value against an array
- WSoD being caused by this piece of code
- I am trying to make a page in the admin section similar to the appearance of the Profile page for users
- WP Page Options Array
- How to make blog post entries appear as input form instead of just text?
- $_POST field value gets altered after “init”