I need help because I do not know what the error means so I am not sure how to correct this. The error states:

.cpp(70) : warning C4996: 'strncpy' was declared deprecated

\string.h(156) : see declaration of 'strncpy'

My code is the following:

// set the tool name
void Tools::setToolName( string toolNameString)
{
   // copy at most 20 characters for the tool name
    const char *toolNameValue = toolNameString.data();
    int length = int(toolNameString.size());
    length = ( length < 20 ? length : 19 );
    strncpy( toolName, toolNameValue, length);
    toolName[ length ] = '\0'; // append null character to lastName
}

Specifically there is an issue with my strncpy:

strncpy( toolName, toolNameValue, length);

Recommended Answers

All 2 Replies

I need help because I do not know what the error means so I am not sure how to correct this. The error states:

.cpp(70) : warning C4996: 'strncpy' was declared deprecated

\string.h(156) : see declaration of 'strncpy'

My code is the following:

// set the tool name
void Tools::setToolName( string toolNameString)
{
   // copy at most 20 characters for the tool name
    const char *toolNameValue = toolNameString.data();
    int length = int(toolNameString.size());
    length = ( length < 20 ? length : 19 );
    strncpy( toolName, toolNameValue, length);
    toolName[ length ] = '\0'; // append null character to lastName
}

Specifically there is an issue with my strncpy:

strncpy( toolName, toolNameValue, length);

This looks the same as this thread. Did you read the answers?
http://www.daniweb.com/forums/thread137036.html

thank you - for some reason I did not see the response and was worried about the error

But those answers did work.

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.