Advertisement
irmantas_radavicius

Untitled

Dec 1st, 2021
481
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. int main(){
  2.     char buffer[] =
  3.         "Hello it is some text which is very long and important!\n"
  4.         "Now it is some short text\n"
  5.         "\n"
  6.         "There was an empty line above\n"
  7.         "Yes\n";       
  8.     printf("The user input looks like this:\n%s\n", buffer);
  9.     printf("We will parse it now using sscanf...\n");  
  10.     int start = 0; 
  11.     for(int i = 0; i < 10; ++i){       
  12.         char line[100] = { 0 }, empty[100] = { 0 };
  13.         if (start < strlen(buffer)){
  14.             int code = sscanf(buffer+start, "%10[^\n]%[^\n]%*c", line, empty);
  15.             start += (strlen(line) + strlen(empty) + 1);
  16.             printf("Read [%s] %d, skip ", line, strlen(line)); 
  17.             printf("[%s] %d, code %d\n", empty, strlen(empty), code);  
  18.         }
  19.     }  
  20.     return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement