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

后端 未结 8 1634
野性不改
野性不改 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:27

    #include 
    int main()
    {
        char a[5],b[10];
        scanf("%2000s %2000[^\n]s",a,b);
        printf("a=%s b=%s",a,b);
    }
    

    Just write s in place of \n :)

提交回复
热议问题