Sign in to follow this  

Any idea's for this problem? (hard to explain here)

Recommended Posts

Alright... What I'm ultimatly trying to do is create my own custom sprintf() like function, i'm going to call it func() in my example. Now, I know a good deal about va_list, va_start, va_end, and va_arg. But my problem is I need to manipulate the data in the arguments before I output it based on it's type. I'll give an example. I'd call this funciton like this: func("This is a var @G this is another var @s", pSomeClass, "some string"); In func() I'd loop through the characters and then at an @ i'd switch() the next character and figure out what manipulation needs to be done, then copy the new proper data into the spot. That's not a problem. The PROBLEM, is that it seems I can't get my argumet list without a proper format string, which I don't have. I even tried making a new dynamically allocated string that replaces all my @x with %s and it still didn't work in va_start().
void func(const char* FakeFmt, ... )
	va_list vaList;
	va_stat(vaList, /*some format that works? already tried to fake it with "%s %s", didn't work =/ */)

	// I put MY characters through a switch to decide what
	// type the argument is, and how to store it

	CONTAINER var = va_arg(vaList, CONTAINER);
	// Here i'd manipulate this data

	// Then copy it to the proper place in my new string i'm crafting
This was a toughy to get clear, ask away if you have any quetions. I'm hoping someone knows how to "complete" this idea, or might have a new way of doing it. Thanks,

Share this post

Link to post
Share on other sites
Well for anyone intersted I solved my own problem of course after I asked about it. Seems to always happen that way.

Seems you don't NEED to use the format string in va_start(vaList, fmt), just the first variable so that it knows where the rest of the argumetns are. so yeah, I'm good to go.

Thanks =)

Share this post

Link to post
Share on other sites
per the documentation, va_start() requires that you pass it the last required arguement so that it knows where the variable arguements start.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this