Draznar

As a new hire as a software engineer for a simulation company, I have been tasked with the problem of porting some programs that were once running and compiling fine on Microsofts Visual C++ 6.0, to the new Microsoft Visual Studios 2005. One specific problem I am currently having is trying to get, the sscanf() function to compile. The code worked fine in the previous compiler, but over here sscanf() just brings up countless build errors. The specific error in the complier is "Error 67 error C3861: 'sscanf': identifier not found c:\release\tenpc\hostemulate\environment.cpp 1406". I have included the <stdio.h> header in all the files that should need it and still it complains of build errors. I also do not beleive this to be a deprication issue because if I change it to sscanf_s() or any other relavent new secure version, the compiler will still give me the same errors. Thats is all the information I know at this point, if any more is needed to help solve my problem, please let me know and I will try to obtain and give it out. Thank you for your help.

EDIT: I have found out that for some reason, a simple scanf() will compile in these files. I don't know if thats helpful at all tho.




Re: Visual C++ Language Broken! sscanf() and/or sscanf_s()

Holger Grund

The usual way to analyze such a problem is to preprocess the to see what happens at that stage. Just temporarily add /P switch to the compilation (See "/P compiler option" in MSDN Library index to find the corresponding IDE setting). This creates environment.i and you can then look where line 1406 would be based on the #line directives.

Does the source line look like what you expect it to be Is sscanf declared in your file

-hg





Re: Visual C++ Language Broken! sscanf() and/or sscanf_s()

Draznar

Ok so I,ve got this Enviroment.i file, and am looking throught it, (it has lots and lots of whitespace) but I am not exactly sure what I am looking for. I don't see my line 1406 anywhere(it doesn't show up in a find) any further clariification



Re: Visual C++ Language Broken! sscanf() and/or sscanf_s()

Draznar

Further Experimentation has shown that if I change a sscanf() to a scanf() they will complie, even if I remove the <stdio.h> header. Since this is the required header for both of these functions, It leaves me puzzeled. Any more questions comments or concerns anybody



Re: Visual C++ Language Broken! sscanf() and/or sscanf_s()

Holger Grund

There is not a #line directive for every line, only for those required to reconstruct the orginial structure. That is you look for #line directives for environment.cpp which is closest to 1406. When you're there, you can just count line to 1406 (so long as there are no intervening #line directives)

Alternatively, you might want to mark the line with sscanf in some way, e.g.: by prepending with a string literal, e.g.:

"here is where I use sscanf": sscanf(..);

The string literal will very likely not be replaced during preprocessing. Therefore you search the .i file for the string literal.

-hg





Re: Visual C++ Language Broken! sscanf() and/or sscanf_s()

Draznar

Ok, I'm back to work and can now continue with this problem. I tried what you suggestted with the string literal and was able to find the spot in the .i file where my code is. The source looks just like it does in the .cpp. I am not really sure what else I am supposed to be able to conclude from this. Any other guidelines / advice to offer



Re: Visual C++ Language Broken! sscanf() and/or sscanf_s()

Draznar

As I mentioned in my previous post

(http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1741055&SiteID=1), I was having some problems getting sscanf() to compile after porting a project from VS C++ 6.0 to VS 2005. In my struggle to get this to work I have been experimenting and testing to see what works and what doesn't. Recently I have been trying to see if I could replicate the problem in a smaller, independant project. Here is one such attempt.

Code Snippet

// crt_sscanf.c

// compile with: /W1

// This program uses sscanf to read data items

// from a string named tokenstring, then displays them.

#include <stdio.h>

int main( void )

{

char tokenstring[] = "15 12 14...";

char s[81];

char c;

int i;

float fp;

// Input various data from tokenstring:

// max 80 character string:

sscanf( tokenstring, "%80s", s ); // C4996

sscanf( tokenstring, "%c", &c ); // C4996

sscanf( tokenstring, "%d", &i ); // C4996

sscanf( tokenstring, "%f", &fp ); // C4996

// Note: sscanf is deprecated; consider using sscanf_s instead

// Output the data read

printf( "String = %s\n", s );

printf( "Character = %c\n", c );

printf( "Integer: = %d\n", i );

printf( "Real: = %f\n", fp );

}

Some of you may recognize this code sample from the MSDN Example on how to use sscanf(), because thats is where I got it from. After creating an empty Win32 console project and adding this example code, I am still unable to compile as there is still a problem with sscanf() somehow. Here are the errors I recieve.

Error 1 error C3861: 'sscanf': identifier not found c:\documents and settings\tengineer\desktop\sscanf_test3\sscanf_test3\main.cpp 18

Error 2 error C3861: 'sscanf': identifier not found c:\documents and settings\tengineer\desktop\sscanf_test3\sscanf_test3\main.cpp 19

Error 3 error C3861: 'sscanf': identifier not found c:\documents and settings\tengineer\desktop\sscanf_test3\sscanf_test3\main.cpp 20

Error 4 error C3861: 'sscanf': identifier not found c:\documents and settings\tengineer\desktop\sscanf_test3\sscanf_test3\main.cpp 21

One other curious test I tried was creating a blank MFC Application and when I complied, I received errors in cstdio in my "C:\Program Files\Microsoft Visual Studio 8\VC\include directory". Here are the 2 errors.

Error 1 error C2039: 'sscanf' : is not a member of '`global namespace'' c:\program files\microsoft visual studio 8\vc\include\cstdio 38

Error 2 error C2873: 'sscanf' : symbol cannot be used in a using-declaration c:\program files\microsoft visual studio 8\vc\include\cstdio 38

So while I found these tests interesting information, I am still confused about why sscanf() or its non depricated version, sscanf_s() does not seem to work at all on my system. I am hoping that once I figure this out I will be able to fix whatever is wrong with my previous post on sscanf() not working after the conversion. Any suggestions, Questions, Comments or Concerns Please help me out.





Re: Visual C++ Language Broken! sscanf() and/or sscanf_s()

einaros

So not even the "default" example works I'd say that this is an header problem. You are either using wrong, or corrupted headers. Try re-installing VS and / or manually verify that your headers actually do contain the right function declarations, and that they are actually being included (verify the include paths in your VS settings).




Re: Visual C++ Language Broken! sscanf() and/or sscanf_s()

Draznar

I'm almost laughing to ask this but, VS2005 should support sscanf() and/or scanf_s() yes



Re: Visual C++ Language Broken! sscanf() and/or sscanf_s()

crescens2k

Yup it does. OIn a fresh install of VS2005 I have just tried the sample given by the MSDN.

------ Build started: Project: sscanf, Configuration: Debug Win32 ------
Compiling...
main.cpp
c:\users\darran\documents\visual studio 2005\projects\sscanf\main.cpp(18) : warning C4996: 'sscanf': This function or variable may be unsafe. Consider using sscanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files\microsoft visual studio 8\vc\include\stdio.h(311) : see declaration of 'sscanf'
c:\users\darran\documents\visual studio 2005\projects\sscanf\main.cpp(19) : warning C4996: 'sscanf': This function or variable may be unsafe. Consider using sscanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files\microsoft visual studio 8\vc\include\stdio.h(311) : see declaration of 'sscanf'
c:\users\darran\documents\visual studio 2005\projects\sscanf\main.cpp(20) : warning C4996: 'sscanf': This function or variable may be unsafe. Consider using sscanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files\microsoft visual studio 8\vc\include\stdio.h(311) : see declaration of 'sscanf'
c:\users\darran\documents\visual studio 2005\projects\sscanf\main.cpp(21) : warning C4996: 'sscanf': This function or variable may be unsafe. Consider using sscanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files\microsoft visual studio 8\vc\include\stdio.h(311) : see declaration of 'sscanf'
Compiling manifest to resources...
Linking...
Embedding manifest...
Build log was saved at "file://c:\Users\Darran\Documents\Visual Studio 2005\Projects\sscanf\Debug\BuildLog.htm"
sscanf - 0 error(s), 4 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========






Re: Visual C++ Language Broken! sscanf() and/or sscanf_s()

Draznar

I did a repair on my copy of VS 2005, and still got the same things. I am going to try to actualy remove it this time and re install from scratch this time. Sadly I doubt it will make a difference, but I'm low on options.... So keep those suggestions comming!