junkyboy
asked on
Printf and Scanf
Can anybody tell me the difference between specific printf() and scanf() functions? For example, what are the difference between wsprintf() and sprintf()? I just need a list of detailed specifics on some of these functions. Thanks!
¨{¨{¨{¨{¨{¨{¨{¨{¨{¨{¨{¨{¨{ ¨{¨{¨{¨{¨{ ¨{¨{¨{
¨„...printf functions▐ <CONIO.H, STDIO.H>
▀▀▀π 0;▀& #9600;` 00;▀ ▀	 600;▀ ;▀&# 9600;π 0;▀& #9600;` 00;▀ ▀	 600;▀ ;
Declaration:
¡ö int cprintf (const char *format [, argument, ...]);
¡ö int fprintf (FILE *stream, const char *format [, argument, ...]);
¡ö int printf (const char *format [, argument, ...]);
¡ö int sprintf (char *buffer, const char *format [, argument, ...]);
¡ö int vfprintf(FILE *stream, const char *format, va_list arglist);
¡ö int vprintf (const char *format, va_list arglist);
¡ö int vsprintf(char *buffer, const char *format, va_list arglist);
Use:
¡ö cprintf sends formatted output to the text window on the screen
¡ö fprintf sends formatted output to a stream
¡ö printf sends formatted output to stdin
¡ö sprintf sends formatted output to a string
¡ö vfprintf sends formatted output to a stream, using an argument list
¡ö vprintf sends formatted output to stdin, using an argument list
¡ö vsprintf sends formatted output to a string, using an argument list
¨„...printf functions▐ <CONIO.H, STDIO.H>
▀▀▀π
Declaration:
¡ö int cprintf (const char *format [, argument, ...]);
¡ö int fprintf (FILE *stream, const char *format [, argument, ...]);
¡ö int printf (const char *format [, argument, ...]);
¡ö int sprintf (char *buffer, const char *format [, argument, ...]);
¡ö int vfprintf(FILE *stream, const char *format, va_list arglist);
¡ö int vprintf (const char *format, va_list arglist);
¡ö int vsprintf(char *buffer, const char *format, va_list arglist);
Use:
¡ö cprintf sends formatted output to the text window on the screen
¡ö fprintf sends formatted output to a stream
¡ö printf sends formatted output to stdin
¡ö sprintf sends formatted output to a string
¡ö vfprintf sends formatted output to a stream, using an argument list
¡ö vprintf sends formatted output to stdin, using an argument list
¡ö vsprintf sends formatted output to a string, using an argument list
This might be a little bit easier to read... ;)
...printf functions <CONIO.H, STDIO.H>
Declaration:
int cprintf (const char *format [, argument, ...]);
int fprintf (FILE *stream, const char *format [, argument, ...]);
int printf (const char *format [, argument, ...]);
int sprintf (char *buffer, const char *format [, argument, ...]);
int vfprintf(FILE *stream, const char *format, va_list arglist);
int vprintf (const char *format, va_list arglist);
int vsprintf(char *buffer, const char *format, va_list arglist);
Use:
cprintf sends formatted output to the text window on the screen
fprintf sends formatted output to a stream
printf sends formatted output to stdin
sprintf sends formatted output to a string
vfprintf sends formatted output to a stream, using an argument list
vprintf sends formatted output to stdin, using an argument list
vsprintf sends formatted output to a string, using an argument list
...printf functions <CONIO.H, STDIO.H>
Declaration:
int cprintf (const char *format [, argument, ...]);
int fprintf (FILE *stream, const char *format [, argument, ...]);
int printf (const char *format [, argument, ...]);
int sprintf (char *buffer, const char *format [, argument, ...]);
int vfprintf(FILE *stream, const char *format, va_list arglist);
int vprintf (const char *format, va_list arglist);
int vsprintf(char *buffer, const char *format, va_list arglist);
Use:
cprintf sends formatted output to the text window on the screen
fprintf sends formatted output to a stream
printf sends formatted output to stdin
sprintf sends formatted output to a string
vfprintf sends formatted output to a stream, using an argument list
vprintf sends formatted output to stdin, using an argument list
vsprintf sends formatted output to a string, using an argument list
printf is for print an out on the screen
scanf is for receive an input for the user
scanf is for receive an input for the user
To add to Ready4Dis:
All 'w' functions are the same as the one without the w but for wide characters (unicode)
-------------------------- ---------- ---------- -------
// wchar_t printf functions
int fwprintf (FILE *stream, const wchar_t *format [, argument, ...]);
int wprintf (const wchar_t *format [, argument, ...]);
int swprintf (wchar_t *buffer, const wchar_t *format [, argument, ...]);
int vfwprintf(FILE *stream, const wchar_t *format, va_list arglist);
int vwprintf (const wchar_t *format, va_list arglist);
int vswprintf(char *buffer, const wchar_t *format, va_list arglist);
-------------------------- ---------- ---------- ---------- -
// scanf functions
// scanf,wscanf: Read formatted data from the standard input stream.
int scanf( const char *format [,argument]... );
int wscanf( const wchar_t *format [,argument]... );
// sscanf,swscanf: Read formatted data from a string.
int sscanf( const char *buffer, const char *format [, argument ] ... );
int swscanf( const wchar_t *buffer, const wchar_t *format [, argument ] ... );
// fscanf, fwscanf: Read formatted data from a stream.
int fscanf( FILE *stream, const char *format [, argument ]... );
int fwscanf( FILE *stream, const wchar_t *format [, argument ]... );
-------------------------- ---------- ---------- ---------- --
Ready4Dis mentioned cprintf. This is not an ANSI function. I believe it is a GNU/Unix function, and there is probably a csanf on that platform. In VC, it is _cprintf and _cscanf:
int _cprintf( const char *format [, argument] ... );
int _cscanf( const char *format [, argument] ... );
-------------------------- ---------- ---------- ---------- --
You mention wsprintf. This is not an ANSI function. There is a Windows function with that name. The win functions are:
int wsprintf(LPTSTR lpOut, LPCTSTR lpFmt, ...);
int wvsprintf(LPTSTR lpOutput, LPCTSTR lpFormat, va_list arglist);
These are equivalents of sprintf and wvsprintf, but use LPTSTR and LPCTSTR instead of char* and const char*. LPTSTR and LPCTSTR are TCHAR* and const TCHAR*, where TCHAR is defined as either a char or WCHAR (wchar_t), depending on compiler setup.
All 'w' functions are the same as the one without the w but for wide characters (unicode)
--------------------------
// wchar_t printf functions
int fwprintf (FILE *stream, const wchar_t *format [, argument, ...]);
int wprintf (const wchar_t *format [, argument, ...]);
int swprintf (wchar_t *buffer, const wchar_t *format [, argument, ...]);
int vfwprintf(FILE *stream, const wchar_t *format, va_list arglist);
int vwprintf (const wchar_t *format, va_list arglist);
int vswprintf(char *buffer, const wchar_t *format, va_list arglist);
--------------------------
// scanf functions
// scanf,wscanf: Read formatted data from the standard input stream.
int scanf( const char *format [,argument]... );
int wscanf( const wchar_t *format [,argument]... );
// sscanf,swscanf: Read formatted data from a string.
int sscanf( const char *buffer, const char *format [, argument ] ... );
int swscanf( const wchar_t *buffer, const wchar_t *format [, argument ] ... );
// fscanf, fwscanf: Read formatted data from a stream.
int fscanf( FILE *stream, const char *format [, argument ]... );
int fwscanf( FILE *stream, const wchar_t *format [, argument ]... );
--------------------------
Ready4Dis mentioned cprintf. This is not an ANSI function. I believe it is a GNU/Unix function, and there is probably a csanf on that platform. In VC, it is _cprintf and _cscanf:
int _cprintf( const char *format [, argument] ... );
int _cscanf( const char *format [, argument] ... );
--------------------------
You mention wsprintf. This is not an ANSI function. There is a Windows function with that name. The win functions are:
int wsprintf(LPTSTR lpOut, LPCTSTR lpFmt, ...);
int wvsprintf(LPTSTR lpOutput, LPCTSTR lpFormat, va_list arglist);
These are equivalents of sprintf and wvsprintf, but use LPTSTR and LPCTSTR instead of char* and const char*. LPTSTR and LPCTSTR are TCHAR* and const TCHAR*, where TCHAR is defined as either a char or WCHAR (wchar_t), depending on compiler setup.
>>are the difference between wsprintf() and sprintf()?
For Windows programmers difference only one:
wsprintf don't undestand float formats. Usually, if I must
fprm buffer in Windows I use wsprintf: works mode speed
and don't use place in code, but fot print float data you
MUST use fprintf.
For Windows programmers difference only one:
wsprintf don't undestand float formats. Usually, if I must
fprm buffer in Windows I use wsprintf: works mode speed
and don't use place in code, but fot print float data you
MUST use fprintf.
ASKER
I could find out all the declarations (since VC++6.0 shows it to you while typing it out).
I might not be getting this correctly: wprintf/wscanf is for wide characters, fprintf/fscanf is for floating points, what are vprintf/vscanf, sprintf and wsprintf, etc. I wanted to know what each prefix stands for. Alex's answer is the closest answer to what I want.
I might not be getting this correctly: wprintf/wscanf is for wide characters, fprintf/fscanf is for floating points, what are vprintf/vscanf, sprintf and wsprintf, etc. I wanted to know what each prefix stands for. Alex's answer is the closest answer to what I want.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK, I guess I more or less understand it now! Thanks!
http://msdn.microsoft.com/library/default.asp?URL=/library/wcedoc/wcecrt/crt2_88.htm
If you are using Microsoft VC, and you have the MSDN installed you can also find it there.