scanf - Scanset doesn't recognize carriage return in c, why? -


i trying take input carriage return press scanset, enter button press.( on windows equals \r\n , right? ). works if write %[^\n]s inside scanf() , not %[^\r]s understanding should work. catch here?

#include <stdio.h>  int main() {     char str[120];      scanf("%[^\r]s", str);      printf("%s",str); } 

you reading standard input. standard input text input stream. in text input streams end of line indicated \n character regardless of whether happens "on windows" or not. purpose of text input stream, among other things, make sure time input data gets scanf, data translated platform-independent form regard line endings @ least. "on windows" \r\n combination replaced lone \n time gets scanf. can't see \r\n reading standard windows input scanf (that unless reading windows text file using unix input stream).


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -