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!

Recommended Answers

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 …

Jump to Post

All 2 Replies

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 ?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.