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 »

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
LPH
New poster
Posts: 34
Joined: Mon Nov 17, 2003 10:41 am

Post by LPH »

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 »

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 »

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;
}
LPH
New poster
Posts: 34
Joined: Mon Nov 17, 2003 10:41 am

Post by LPH »

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

Return to “C++”