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
Post a Comment