input a iteger like a string

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
User avatar
nahid
New poster
Posts: 18
Joined: Wed Oct 04, 2006 8:59 pm
Location: DHAKA,BANGLADESH
Contact:

input a iteger like a string

Post by nahid » Mon Nov 13, 2006 5:57 am

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)

misof
A great helper
Posts: 430
Joined: Wed Jun 09, 2004 1:31 pm

Post by misof » Mon Nov 13, 2006 2:16 pm

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?

DIR EN GREY
New poster
Posts: 12
Joined: Thu Nov 09, 2006 11:49 am

Post by DIR EN GREY » Mon Nov 13, 2006 11:23 pm

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.
Do you understand my English???

Vexorian
Learning poster
Posts: 100
Joined: Sat Aug 26, 2006 5:50 am

Post by Vexorian » Tue Nov 14, 2006 4:16 am

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

Post Reply

Return to “C++”