Advertisement
irmantas_radavicius

Untitled

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