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

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

    use getchar and a while that look like this

    while(x = getchar())
    {   
        if(x == '\n'||x == '\0')
           do what you need when space or return is detected
        else
            mystring.append(x)
    }
    

    Sorry if I wrote a pseudo-code but I don't work with C language from a while.

提交回复
热议问题