Page 1 of 1

input a iteger like a string

Posted: Mon Nov 13, 2006 5:57 am
by nahid
I need to input two very long int in a single line seperated by a space. in this case "gets()" does not terminate by space(" ") . as the number of digits is undefined , i can't use "scanf()" with "while{}" loop.
a sample input is given .

Code: Select all

/*************sample input*****************/

2(test case)
121215453521 555555555555511111111(case 1)
5555555555555555555 44444444444444444(case 2)

Posted: Mon Nov 13, 2006 2:16 pm
by misof
What do you mean by saying "can't use scanf"? What you need is easily done using scanf("%s"). Is this somehow forbidden and you need another possibility?

Posted: Mon Nov 13, 2006 11:23 pm
by DIR EN GREY
As misof said, enve if the number of digits is undefined, you can use scanf. In your case, I think the number of integers is always two (because you wrote) , so you can use scanf as the follows:

Code: Select all

scanf("%s %s", string_a, string_b);
There is no problem.

Posted: Tue Nov 14, 2006 4:16 am
by Vexorian
you *can* use scanf, but you'd also need to know the number of digits anyways because you need to declare the char array don't you?

This is C++, you could just use STL ...

But for these kinds you can use scanf("%c",&c) to get a character. And just use it inside a while