Thread: Help with deprecated functions

  1. #1
    Registered User
    Join Date
    Sep 2015
    Posts
    13

    Help with deprecated functions

    I am trying to extract an environment variable and append a string to it. This is my code:

    const char* env_temp = getenv("TEMP");
    char buff[1024];
    strcpy(buff, env_temp);
    strcat(buff, "\blahblah");


    When compiling in VS 2015 I get:
    error C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead.
    error C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead.
    error C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead.


    I have tried fiddling with these to no avail (I am not a C++ programmer). Can anyone help?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    First off, That's C code not C++.

    Read this
    Compiler Warning (level 3) C4996

    You can disable it by putting this line right at the start of your code (before any #includes)
    Code:
    #define _CRT_SECURE_NO_WARNINGS
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. <ctime> localtime deprecated in VS 2010?
    By Imanuel in forum C++ Programming
    Replies: 9
    Last Post: 12-29-2012, 10:17 PM
  2. 'strcpy' was declared deprecated warning
    By rahulsk1947 in forum C++ Programming
    Replies: 4
    Last Post: 06-14-2007, 09:11 AM
  3. new error when compiling, deprecated use of cast expressions....
    By willc0de4food in forum Windows Programming
    Replies: 4
    Last Post: 10-02-2006, 05:26 AM
  4. Fopen Deprecated
    By EvilGuru in forum C Programming
    Replies: 11
    Last Post: 10-16-2005, 08:54 AM
  5. DirectX 9.0c deprecated parts?
    By Rune Hunter in forum C# Programming
    Replies: 2
    Last Post: 06-26-2005, 09:35 AM

Tags for this Thread