How can I scan strings with spaces in them using scanf()? [duplicate]

Rather than the answers that tell you not to use scanf(), you can just the the Negated scanset option of scanf():

scanf("%99[^\n]",comment); // This will read into the string: comment 
                           // everything from the next 99 characters up until 
                           // it gets a newline

Leave a Comment