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

Winapi c++: DialogBox hangs when breaking a loop -

vb.net - Font adding using PDFsharp -

javascript - jQuery iScroll clickable list elements while retaining scroll? -