How to read from input until newline is found using scanf()?

后端 未结 8 1618
野性不改
野性不改 2020-11-30 05:58

I was asked to do a work in C when I\'m supposed to read from input until there\'s a space and then until the user presses enter. If I do this:

scanf(\"%2000         


        
8条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 06:48

    //increase char array size if u want take more no. of characters.

    #include 
    int main()
    {
        char s[10],s1[10];
        scanf("\n");//imp for below statement to work
        scanf("%[^\n]%c",s);//to take input till the you click enter
        scanf("%s",s1);//to take input till a space
        printf("%s",s);
        printf("%s",s1);
        return 0;
    }
    

提交回复
热议问题