Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdbool.h>
- #include <stdio.h>
- #include <string.h>
- #include <errno.h>
- int main() {
- FILE *file = fopen("data.txt", "r");
- if(file == NULL) {
- fprintf(stderr, "%s\n", strerror(errno));
- exit(1);
- }
- char buffer[128];
- int month;
- int day;
- int hour;
- int minute;
- int number;
- char mock;
- while(fgets(buffer, sizeof(buffer), file) != NULL) {
- if(sscanf(buffer, "[1518-%d-%d %d:%d] falls asleep%c", &month, &day, &hour, &minute, &mock) == 5 && mock == '\n') {
- printf("[1518-%d-%d %d:%d] falls asleep\n", month, day, hour, minute);
- continue;
- }
- if(sscanf(buffer, "[1518-%d-%d %d:%d] wakes up%c", &month, &day, &hour, &minute, &mock) == 5 && mock == '\n') {
- printf("[1518-%d-%d %d:%d] wakes up\n", month, day, hour, minute);
- continue;
- }
- if(sscanf(buffer, "[1518-%d-%d %d:%d] Guard #%d begins shift%c", &month, &day, &hour, &minute, &number, &mock) == 6 && mock == '\n') {
- printf("[1518-%d-%d %d:%d] Guard #%d begins shift\n", month, day, hour, minute, number);
- continue;
- }
- printf("Zły format lini\n");
- }
- fclose(file);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement