file - C, how to stop stdin from outputting after each enter by the user? -


i new c , encountering problem stdin cannot find solution to. program either reads file(s) or reads stdin if no arguments (files) provided user.

if user doesn't supply arguments automatically read stdin. program supposed take in input (from file or stdin) , remove blank lines it.

my problem arises when program reads stdin. every time user types presses enter program automatically out puts results. when i'd prefer enter newline.

how can make program waits user hit eof instead of each enter?

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #define numchars 1024  int main(int argc, char** argv){   int good_file = 0;    if (argc <= 1) {     good_file++;     test(stdin);   }    file* files[argc - 1];   int i;   (i = 0; < argc - 1; i++) {     if ((files[i] = fopen(argv[i + 1], "r")) == null) {       continue;     } else {       good_file++;       test(files[i]);     }   }    if (!good_file) {     fprintf(stderr, "error!\n");   } }  int test(file *file) {   char buffer[numchars];    while (fgets(buffer, numchars, file) != null)     part2(buffer);   fclose(file); }  int part2(char *buffer) {   if (!is_all_white(buffer)) {     fputs(buffer, stdout);   } }  int is_all_white(char *s) {   while (*s) {     if (!('\n' == *s || '\t' == *s || ' ' == *s))       return 0;     s += 1;   }   return 1; } 

i appreciate feedback!

it isn't issue stdin per se - if want wait output data, have store it. write file , read afterward. use malloc , realloc store data in memory. mainly, if don't want data output on every line, need not output on every line.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -