Click here to Skip to main content
16,007,504 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
get error like this in visual studio 2012:
error C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS

also get this in "char *cPtr = strtok (cStr, " ");"





C#
void parser(string line, int fileNo, class HashTable & HT, frequencyList FL[])
{
        // Variables declarations
        //char * cStr, * cPtr;
        string tempString;



        char* cStr=new char[line.length()+1];
        strcpy(cStr ,line.c_str());

        /*
        // Define cStr = the size of line + 1
        // Copy the string line to char * cStr
        cStr = new char [line.size() + 1];
        strcpy (cStr, line.c_str());
        */
        // Parese cStr by " "
        char *cPtr = strtok (cStr, " ");
        while (cPtr != NULL)
        {
                if (strcmp(cPtr, "</TEXT>") != 0 && *cPtr != '.')
                {
                        tempString = string(cPtr);

                        // Call removeCommaBehind function to remove , behind word
                        removeCommaBehind(tempString);

                       
                     
                        if(tempString.compare(",") != 0)
                        if(tempString.compare(".") != 0)
                        if(tempString.compare("=") != 0)
                        {
                                // Call countFrequency() function
                                countFrequency(tempString, FL);
                        }
                }
                cPtr = strtok(NULL, "()/ ");
        }
        delete[] cStr;
}
Posted
Updated 16-Jan-14 1:40am
v2

Here you can find the solution for your question:

Stackoverflow
 
Share this answer
 
Comments
mahla.r 16-Jan-14 11:31am    
i don't want use this function
do you have any suggest function in c++
HellMaster[cz] 17-Jan-14 0:49am    
Solution 4 seems to be the best way for you. I program only in C so I would recommend you strncpy(). Maybe not safer then strcpy_s(), but much safer then strspy(). :-)

Good luck
The error message itself suggest the fix: use the strcpy_s[^] and strtok_s[^] functions.
 
Share this answer
 
The error message itself already states two possible solutions. You could also google the error code or directly jump to the error help using F1 to find this article[^]

In short: inform yourself about MicroSofts reasons to introduce the new functions and deprecate the old ones, then decide whether you want to use them or not, and change your code accordingly, or use _CRT_SECURE_NO_WARNINGS.

If you go for the latter option, don't put the definition into your code, add it to your precompile settings. It's non-standard C++, so no point polluting your code with it...
 
Share this answer
 
You could always try writing C++ rather than some half-cocked C/C++ hybrid. For tokenising strings have a look at what std::string and std::stringstream can do for you.
 
Share this answer
 
Comments
CPallini 16-Jan-14 12:22pm    
My 5. Not able to understand Mr. Downvoter reasons.
memmove.
like this:
char szBuffSrc[128];
char szBuffDst[128];
memmove(szBuffDst, szBuffSrc, strlen(szBuffSrc));
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900