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

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -