Page 1 of 1

Who has easier variant?

Posted: Fri Oct 28, 2005 11:01 am
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

Posted: Fri Oct 28, 2005 7:20 pm
by LPH
i can only think about using strtok+sscanf/atoi/atod.

any better suggestions?

Posted: Sat Oct 29, 2005 4:12 am
by Artikali
Could you give example, which is stayed above.
only input and output, not whole program
Thanks

Posted: Sat Oct 29, 2005 5:00 am
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;
}

Posted: Sun Nov 06, 2005 4:00 am
by LPH
[quote="Bj