5 Replies - 13425 Views - Last Post: 20 July 2009 - 11:06 AM Rate Topic: -----

#1 ClanguageLearner   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-July 09

Gettig a scanf warning.

Posted 19 July 2009 - 08:52 PM

Hello everyone,

I need some help with one of the warnings I have been getting. My program compiles just fine, however, I get the following warning:

warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead.
. can someone please explain what difference does it make by including scanf_s vs. scanf?

Here my code:

#include <stdio.h>

int main(void)

{
int n=0;
int nO=0;
int nT=0;
int nTh=0;
int nF=0;
int nFi=0;




printf("Please enter a number :");
scanf("%d",&n);


nO = n/10000;
nT = (n % 10000) /1000;
nTh = (n % 1000) /100;
nF = (n % 100) /10;
nFi = n % 10;



printf("\n%4d%4d%4d%4d%4d\n", nO, nT, nTh, nF, nFi);
printf("\n%4d%4d%4d\n", nTh, nF, nFi);
printf("\n%4d%\n", nFi);

return 0;

}

I am using Microsoft Visual C++ 2008 expression edition.

This post has been edited by ClanguageLearner: 19 July 2009 - 09:03 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Gettig a scanf warning.

#2 Guest_c.user*


Reputation:

Re: Gettig a scanf warning.

Posted 19 July 2009 - 09:01 PM

scanf("%10d",&n);

Quote

Consider using scanf_s

it is mean that if you don't know what is it mean then you must use windows compiler for all of your life and windows compiler works only in windows

This post has been edited by c.user: 19 July 2009 - 09:04 PM

Was This Post Helpful? 0

#3 ClanguageLearner   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-July 09

Re: Gettig a scanf warning.

Posted 19 July 2009 - 09:17 PM

thanks c.user but this does not help much
Was This Post Helpful? 0
  • +
  • -

#5 Ancient Dragon   User is offline

  • D.I.C Addict
  • member icon

Reputation: 82
  • View blog
  • Posts: 679
  • Joined: 19-July 09

Re: Gettig a scanf warning.

Posted 19 July 2009 - 09:26 PM

You are using a Microsoft compiler. Microsoft, in its infinite wisdom, declared many C functions depreciated, and it did that without authority of the C or C++ standards committee. Those functions are not depreciated.

You can suppress that warning message like this:
#pragma warning(disable: 4996)



More information here

But I won't debate the usefullness of those substitute Microsoft-Specific functions, such as scanf_s, because they are safer than the originals, and in time they may find their way into the C and C++ standards. But that is not yet, so if you use them you will have non-portable programs.

This post has been edited by Ancient Dragon: 19 July 2009 - 09:28 PM

Was This Post Helpful? 1
  • +
  • -

#6 Guest_c.user*


Reputation:

Re: Gettig a scanf warning.

Posted 20 July 2009 - 01:23 AM

Quote

because they are safer than the originals

it is better if professionals will develop this
it is necessary to have safe OS for advice to users anything about safeness
Was This Post Helpful? 0

#7 codefreak.   User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 79
  • Joined: 11-July 09

Re: Gettig a scanf warning.

Posted 20 July 2009 - 11:06 AM

Get up-to-date with C++ standards.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1