0

Hi!
I have to write the programm, which will receive any number (at sec) and calculate it to weeks, days, hours, minutes and sec; for e.x. 4102 sec ---> 1h 8m and 22s

The problem is that it's forbidden to use atoi(), scanf() and simmilar functions. Insead of them, I should use getchar(), putchar(), printf().
So, I start with a converting string to int.

#include <stdio.h>
#include <stdlib.h>

/* MAIN */
int main()
{
    int number;
    int l;

    while ((number = getchar()) != EOF)
    {
      l = cislo - '0';
      putchar(l);
    }

    return 0;
}

It doesn't work as I want :( I hope you will help me. I'll accept any advice to write the program. Thank you!

Edited by Alex Starkov: mistake

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Alex Starkov
1

I'm not sure what you're trying to do here. In case you are trying to convert a string into an int, this would work:

l = l * 10 + (number - '0');

So, when the loop terminates, l will have the integer needed.

By the way, what is cislo ?

0

myk45,
Thank you for answer! I'll try your suggestion.
P.S. I'm mistaken, there should be "number".

Edited by Alex Starkov: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.