DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   formated file reading problem (http://www.daniweb.com/forums/thread108001.html)

kux Feb 7th, 2008 5:50 am
formated file reading problem
 
As i knew the <stdarg.h> header should have the following function

int vfscanf(FILE *stream, const char *format, va_list ap);

but under Visual Studio 2005, after including the header and calling the function i get
'vfscanf': identifier not found

if the function is not declared, can u tell me some simmilar functions that do the same
thing and have the same parameters?

thx

Passmark Feb 7th, 2008 6:02 am
Re: formated file reading problem
 
I don't think it is supported. A replacement might be fscanf() + some extra code, but it really depends on what you are doing with with vfscanf.

kux Feb 7th, 2008 6:12 am
Re: formated file reading problem
 
Quote:

Originally Posted by Passmark (Post 528376)
I don't think it is supported. A replacement might be fscanf() + some extra code, but it really depends on what you are doing with with vfscanf.

hmmm, what i am doing is that i want to wrap my formated file read in a File class that i design myself so that it throws exceptions for every problem that might occur.
what i want to is to have a Scan method in my File class that looks like

void File::Scan ( const char * Format, ... )
{
va_list objArgs;
va_start( objArgs, pcFormat );
vfscanf( m_pFile, pcFormat, objArgs ); // m_pFile is the file handle
va_end( objArgs );
}

this is actually wraping fscanf in File::Scan

kux Feb 7th, 2008 6:13 am
Re: formated file reading problem
 
lol, it replaced : fs with the smiley , u know what i mean actually :P :))

niek_e Feb 7th, 2008 8:58 am
Re: formated file reading problem
 
Did some research for you, and there is a workaround :

#ifndef __stdio_h__
#include <stdio.h>
#define __stdio_h__
#endif

int vsscanf_s (const char * src, const size_t length, const char * format, va_list argList);
int vsscanf_s (const char * src, const size_t length, const char * format, va_list argList)
{
    return _snscanf_s (src, length, format, * (void **) argList);
}

int vsscanf (const char * src, const char * format, va_list argList);
int vsscanf (const char * src, const char * format, va_list argList)
{
    return sscanf (src, format, * (void **) argList);
}
Just throw that in the file where you're using vsscanf and it should work again.
If you use this code, use the vsscanf_s instead of the vsscanf if you want to avoid getting anoying "sscanf was declared deprecated" warnings.

Hope this helps. If it doesn't, post some sample data from your file and you'll get advice how to make your own function for it.

Niek

WaltP Feb 7th, 2008 8:01 pm
Re: formated file reading problem
 
Quote:

Originally Posted by kux (Post 528383)
lol, it replaced : fs with the smiley , u know what i mean actually :P :))

That's why we insist on people leaning to use CODE tags, as mentioned in the rules you read when you signed up.


All times are GMT -4. The time now is 8:11 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC