Programming WIndows? DO you have to use printf like functions?

Started by
7 comments, last by TriWolf 23 years, 1 month ago
I am reading Charles Petzoid''s Book "Programming Windows Fifth Edition". Now frankly I have only done C++ so I don''t know much about printf and so forth functions. Is there another way? Here''s the program. ----------------------------------------------------------------- #include #include #include int CDECL MessageBoxPrintf (TCHAR * szCaption, TCHAR * szFormat, ...) { TCHAR szBuffer [1024]; va_list pArgList; va_start (pArgList, szFormat); _vsntprintf(szBuffer, sizeof(szBuffer)/sizeof (TCHAR), szFormat, pArgList); va_end(pArgList); return MessageBox(NULL, szBuffer, szCaption, 0); } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { int cxScreen, cyScreen; cxScreen = GetSystemMetrics(SM_CXSCREEN); cyScreen = GetSystemMetrics(SM_CYSCREEN); MessageBoxPrintf(TEXT ("ScrnSize"), TEXT ("The screen is %i pixels wide by %i pixels high."), cxScreen, cyScreen); return 0; } Timothy "TriWolf" Russell
Timothy "TriWolf" Russell
Advertisement
I''ve seen this kind of code before, it''s just a way of making a function that has an unspecific number of arguments. The va_ stuff is dealing with the extra arguments. _vsntprintf is like sprintf but it takes a constant number of parameters to construct the string you want in your message box.

AFAIK this is really the only way to make a function with no specified limit to the number of arguments it takes. I have never seen any code that does the same thing in a different way that is easier.

printf, sprintf, fprintf and all those kind of functions are really very simple to use. I am sure it won''t take much time to get to know them.

Harry.
Harry.
My advise is to learn to use the C Standard i/o functions. They''ll make your coding a lot easier later on. I have in many circumstances run in to things that you simple cannot do with the C++ Stream i/o functions.

"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
Resist Windows XP''s Invasive Production Activation Technology!
http://www.gdarchive.net/druidgames/
You could use a stringbuffer I think, just use it like you would use cout, and then get the c-string from the stringbuffer
Could anyone recommend a website for learning the C i/o functions. Becuase I can''t afford yet another book right now.

Timothy "TriWolf" Russell
Timothy "TriWolf" Russell
> Could anyone recommend a website for learning the C i/o
> functions. Becuase I can''t afford yet another book right now.

Under MSVC++ : check the doc.
Under Linux/Unix : just type "man printf" in a xterm.
Other : ???

If you don''t find anything, send me a mail and I''ll send you the whole printf/scanf/etc... specifications.
www.introl.com/introl-demo/Libraries/C/ANSI-C/contents.html

A free reference to most standard functions in the standard library.

-----------------------------

A wise man once said "A person with half a clue is more dangerous than a person with or without one."

The Micro$haft BSOD T-Shirt
-----------------------------A wise man once said "A person with half a clue is more dangerous than a person with or without one."The Micro$haft BSOD T-Shirt
If you don''t like that (I couldn''t even connect with that address), go here and download BCHelp.zip. Unzip it, run the help file. Click the index tab, and type in stdio.h. From there you can see many links to each of its functions, with examples.

"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
Resist Windows XP''s Invasive Production Activation Technology!
http://www.gdarchive.net/druidgames/
Thanks all the help is great of you. Oh and Null and void the I did find his page and here is the correct address.

http://www.introl.com/introl-demo/Libraries/C/ANSI_C/contents.html
Once agian thanks and I feel a lot better. I''m on my way to working in the gaming industry .

Timothy "TriWolf" Russell
Timothy "TriWolf" Russell

This topic is closed to new replies.

Advertisement