Who has easier variant?

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

Moderator: Board moderators

Post Reply
Artikali
Learning poster
Posts: 68
Joined: Wed Sep 21, 2005 5:27 pm

Who has easier variant?

Post by Artikali » Fri Oct 28, 2005 11:01 am

INPUt
format : string & integer * float (string)
For Example : I think & 10 *20.5(how are you)

OUTPUT
Format:
string
integer
floar
string

For Example
I think
10
20.5
how are you

User avatar
LPH
New poster
Posts: 34
Joined: Mon Nov 17, 2003 10:41 am

Post by LPH » Fri Oct 28, 2005 7:20 pm

i can only think about using strtok+sscanf/atoi/atod.

any better suggestions?
LPH [acronym]
= Let Program Heal us
-- New Uncyclopedian Dictionary, Minmei Publishing Co.

Artikali
Learning poster
Posts: 68
Joined: Wed Sep 21, 2005 5:27 pm

Post by Artikali » Sat Oct 29, 2005 4:12 am

Could you give example, which is stayed above.
only input and output, not whole program
Thanks

Bj
New poster
Posts: 24
Joined: Mon Oct 17, 2005 1:39 am
Location: Sweden

Post by Bj » Sat Oct 29, 2005 5:00 am

I am not completely sure this will work, try it. Sorry for the dumb variable names.

Code: Select all

int main()
{
	string test = "I think & 10*20.5(how are you)";
	char a[30];
	int b;
	float c;
	char d[30];

	sscanf(test.c_str(), "%[A-Z,a-z, ] & %d * %f (%[A-Z,a-z, ])", a, &b, &c, d);

	cout << a << endl;
	cout << b << endl;
	cout << c << endl;
	cout << d << endl;

	return 0;
}

User avatar
LPH
New poster
Posts: 34
Joined: Mon Nov 17, 2003 10:41 am

Post by LPH » Sun Nov 06, 2005 4:00 am

[quote="Bj
LPH [acronym]
= Let Program Heal us
-- New Uncyclopedian Dictionary, Minmei Publishing Co.

Post Reply

Return to “C++”