Advertisement
homer512

scanf read to end of line

May 18th, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. /*
  4.  * Example input:
  5.  * CSCE 1010 Introduction to Computer Science
  6.  */
  7.  
  8. static void parse_error()
  9. {
  10.   fprintf(stderr, "Invalid input\n");
  11. }
  12.  
  13. int main(void)
  14. {
  15.   char prefix[5];
  16.   int number;
  17.   char name[101];
  18.   while(!feof(stdin)) {
  19.     if(! scanf("%4s", prefix))
  20.       continue; // empty line                                                                                                                                                                    
  21.     if(! scanf("%d %100[^\n]", &number, name)) {
  22.       parse_error();
  23.       break;
  24.     }
  25.     printf("%s\t%d\t%s\n", prefix, number, name);
  26.   }
  27.   return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement