Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(){
- char buffer[] =
- "Hello it is some text which is very long and important!\n"
- "Now it is some short text\n"
- "\n"
- "There was an empty line above\n"
- "Yes\n";
- printf("The user input looks like this:\n%s\n", buffer);
- printf("We will parse it now using sscanf...\n");
- int start = 0;
- for(int i = 0; i < 10; ++i){
- char line[100] = { 0 }, empty[100] = { 0 };
- if (start < strlen(buffer)){
- int code = sscanf(buffer+start, "%10[^\n]%[^\n]%*c", line, empty);
- start += (strlen(line) + strlen(empty) + 1);
- printf("Read [%s] %d, skip ", line, strlen(line));
- printf("[%s] %d, code %d\n", empty, strlen(empty), code);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement