Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

This function or variable may be unsafe visual studio

I got a problem on visual studio. I try to use the localtime function from "time.h".

Visual studio tells me it's an unsafe function. However, I have tu use this one for my school exercice. I saw that you can disable this unsafe error by going in the project properties, build tab, and check "enable unsafe code".

Nevertheless, I don't have a build tab, as you can see there : http://puu.sh/4NkYC.png

I'm using windows 7 and visual studio 2012 Ultimate. It looks like the "build tab" and "enable unsafe code" has vanished :/ Maybe you know how to fix that ?

thank's a lot :)

like image 553
QuentinRM Avatar asked Oct 11 '13 15:10

QuentinRM


2 Answers

Visual Studio (VS) compiler gives this error. It's simple to get rid of this problem.

  1. Go to your VS context menu Project>Properties.
  2. Click Configuration>Properties>C/C++>Preprocessor.
  3. Edit Preprocessor Definitions and add _CRT_SECURE_NO_WARNINGS last empty line.

This compile warning will be gone.

like image 53
Umut D. Avatar answered Oct 10 '22 04:10

Umut D.


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h> 
#include <stdlib.h> 
#include <time.h> 
char counter_str[10];

int main()
{ 
  time_t my_time = time(NULL)// declaring argument of time();
  sprintf(counter_str,ctime(&my_time));//fetch current time
  printf(counter_str);

}
like image 38
Sreejith Sathyan Avatar answered Oct 10 '22 04:10

Sreejith Sathyan