fgets - Get the whole input of a string in C -


#include char option[64],line[256];  main()  {  printf(">>") (fgets(line, sizeof(line), stdin)) {             if (1 == sscanf(line, "%s", option)) {             }     } print(option) } 

will first word, example

/>>hello world

would output

/>>hello

#include <stdio.h>  int main(){     char option[64],line[256];      printf(">>");     if(fgets(line, sizeof(line), stdin)) {         if (1 == sscanf(line, "%[^\n]%*c", option)) {//[^\n] isn't newline chars              printf("%s\n", option);         }     }     return 0; } 

Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -