Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <stdbool.h>
- /**
- Entrée
- 8:12
- 14:32
- Sortie attendue
- 380
- **/
- long chars_to_int(const char *s);
- int main()
- {
- char depart[6];
- scanf("%[^\n]", depart); fgetc(stdin);
- char arrive[6];
- scanf("%[^\n]", arrive);
- // Write an answer using printf(). DON'T FORGET THE TRAILING \n
- // To debug: fprintf(stderr, "Debug messages...\n");
- char *ptr = strtok(arrive, ":");
- long hourArr = chars_to_int(ptr);
- ptr = strtok(NULL, ":");
- long minArr = chars_to_int(ptr);
- ptr = strtok(depart, ":");
- long hourDep = chars_to_int(ptr);
- ptr = strtok(NULL, ":");
- long minDep = chars_to_int(ptr);
- long sum = ((hourArr-hourDep) * 60) + (minArr - minDep);
- printf("%ld", sum);
- return 0;
- }
- long chars_to_int(const char *s) {
- char *endptr;
- long num = strtol(s, &endptr, 10);
- if (*endptr == '\0') {
- return num;
- } else {
- exit(-1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement