Hello guys

You rookie here. been trying to run a code but I am getting this weird error that I have not seen before. I have attached a copy of the error and the part of the code it refers to. Thanks for your help

GCard

1>------ Build started: Project: Memory, Configuration: Debug Win32 ------
1>Compiling...
1>memory.cpp
1>c:\documents and settings\myfolder\desktop\mydocs\c\visual\memory\memory.cpp(57) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>        c:\program files\microsoft visual studio 9.0\vc\include\string.h(74) : see declaration of 'strcpy'
1>c:\documents and settings\myfolder\desktop\mydocs\c\visual\memory\memory.cpp(59) : error C2065: 'newchar' : undeclared identifier
1>c:\documents and settings\myfolder\desktop\mydocs\c\visual\memory\memory.cpp(89) : error C2065: 'sSaleperson' : undeclared identifier
1>Build log was saved at "file://c:\Documents and Settingsmyfolder\desktop\mydocs\c\Visual\Memory\Debug\BuildLog.htm"
1>Memory - 2 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

code:

Boolean CSalesRegion::SetDetails(char *psSalesPerson,char *psRegion)
{
    if(psSalesPerson==NULL || psRegion==NULL)
    {
       return FALSE;
    }

    m_psSalesPerson=new char[strlen(psSalesPerson)+1];
    if(m_psSalesPerson==NULL)
    {
       return FALSE;
    }
    strcpy(m_psSalesPerson, psSalesPerson);

    m_psRegion=newchar[strlen(psRegion)+1];
    if(m_psRegion==NULL)
    {
       return FALSE;
    }
    strcpy(m_psRegion, psRegion);
    return TRUE;
}

Hello guys

You rookie here. been trying to run a code but I am getting this weird error that I have not seen before. I have attached a copy of the error and the part of the code it refers to. Thanks for your help

GCard

1>------ Build started: Project: Memory, Configuration: Debug Win32 ------
1>Compiling...
1>memory.cpp
1>c:\documents and settings\myfolder\desktop\mydocs\c\visual\memory\memory.cpp(57) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>        c:\program files\microsoft visual studio 9.0\vc\include\string.h(74) : see declaration of 'strcpy'
1>c:\documents and settings\myfolder\desktop\mydocs\c\visual\memory\memory.cpp(59) : error C2065: 'newchar' : undeclared identifier
1>c:\documents and settings\myfolder\desktop\mydocs\c\visual\memory\memory.cpp(89) : error C2065: 'sSaleperson' : undeclared identifier
1>Build log was saved at "file://c:\Documents and Settingsmyfolder\desktop\mydocs\c\Visual\Memory\Debug\BuildLog.htm"
1>Memory - 2 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Boolean CSalesRegion::SetDetails(char *psSalesPerson,char *psRegion)
{
	if(psSalesPerson==NULL || psRegion==NULL)
	{
	   return FALSE;
	}

	m_psSalesPerson=new char[strlen(psSalesPerson)+1];
	if(m_psSalesPerson==NULL)
	{
	   return FALSE;
	}
	strcpy(m_psSalesPerson, psSalesPerson);
	
	m_psRegion=newchar[strlen(psRegion)+1];
	if(m_psRegion==NULL)
	{
	   return FALSE;
	}
	strcpy(m_psRegion, psRegion);
	return TRUE;
}

First, the correct part is:

m_psRegion=new char[strlen(psRegion)+1];

Don't forget spaces ))

Tell me the type of m_psRegion and m_psSalesPerson

>settings\myfolder\desktop\mydocs\c\visual\memory\memory.cpp(89) : error C2065: 'sSaleperson' : undeclared identifier

Correct is psSalePerson.

The capitals are different from usual letters in C++.

Here is the class definition

class CSalesRegion
{
private:
	char *m_psSalesPerson;
	char *m_psRegion;
	static short m_nObjectCount;
public:
	CSalesRegion();
	~CSalesRegion();
	Boolean SetDetails(char *psSalesPerson, char *psRegion);
	void PrintDetails(void);
}
1>c:\documents and settings\myfolder\desktop\mydocs\c\visual\memory\memory.cpp(57) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

That is a Microsoft-Specific warning message. M$ doesn't like using the standard C style string functions like strlen(), strcpy() etc because they have potential problems of overwriting buffers, which is true because they are dangerous if extra care isn't taken to insure program safety.

If you use the replacement function identified in the warning message then your program will not be able to be compiled by other programs because those replacement functions are not standard functions. If you have to hand in the source code of your assignment to your teacher, then your teacher can't compile it without using the same version of the Microsoft compiler that you used.

My suggestion to students is to ignore that warning message and use #pragma warning(disable: 4996) to prevent the compiler from issuing it -- unless of course your teacher has instructed you to do otherwise.

Here is the class definition

class CSalesRegion
{
private:
	char *m_psSalesPerson;
	char *m_psRegion;
	static short m_nObjectCount;
public:
	CSalesRegion();
	~CSalesRegion();
	Boolean SetDetails(char *psSalesPerson, char *psRegion);
	void PrintDetails(void);
}

We usually put ; after class:

class A {
...
};

<snip>
My suggestion to students is to ignore that warning message and use #pragma warning(disable: 4996) to prevent the compiler from issuing it -- unless of course your teacher has instructed you to do otherwise.

Or, follow the advice from M$

#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_NONSTDC_NO_DEPRECATE

Use these #define's to halt the many warnings given by
Visual C++ 2005/2008 for use of "unsafe" functions.
Place these before the #include<cstring> or #include<string>

see here for a full list of the functions that have
secure variations available

1>c:\documents and settings\myfolder\desktop\mydocs\c\visual\memory\memory.cpp(57) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

That is a Microsoft-Specific warning message. M$ doesn't like using the standard C style string functions like strlen(), strcpy() etc because they have potential problems of overwriting buffers, which is true because they are dangerous if extra care isn't taken to insure program safety.

If you use the replacement function identified in the warning message then your program will not be able to be compiled by other programs because those replacement functions are not standard functions. If you have to hand in the source code of your assignment to your teacher, then your teacher can't compile it without using the same version of the Microsoft compiler that you used.

My suggestion to students is to ignore that warning message and use #pragma warning(disable: 4996) to prevent the compiler from issuing it -- unless of course your teacher has instructed you to do otherwise.

THANK YOU for this #pragma warning(disable: 4996) that error was so annoying, fixing it inevitably led to more problems.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.