?
Solved

Where Did I Go Wrong?

Posted on 2008-10-10
7
Medium Priority
?
2,492 Views
Last Modified: 2013-12-14
The below is the warning I get when I try to debug inputs to my program:
warning C4996: 'scanf' was declared deprecated

It refers to this string:  scanf(" %c%c%c", &first, &second, &third);

I cannot figure out what is wrong.  Can anyone help?
0
Comment
Question by:Noo2this
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 8

Expert Comment

by:StrongBad_Rules
ID: 22692679
Could you put the whole code on here or at least the declarations?
0
 

Author Comment

by:Noo2this
ID: 22692689

int
main(void)
{
char first, second, third; /* input - first 3 letters of your name */
int yard_length, house_length; /* input - yard and house length */
int yard_width, house_width; /* input - yard and house width */
int grass_area; /* output - what you are working with */
int time_required; /* output - time required to cut the grass */
 
/* Get and display the customer's name. */
printf("Type in first 3 letters of your name and press return> ");
scanf(" %c%c%c", &first, &second, &third);
printf("Hello %c%c%c, let's see how big your yard is.\n", first, second, third);
	

Open in new window

0
 
LVL 8

Expert Comment

by:Thejaka
ID: 22692854
This is a microsoft CRT related warning. You can use

#pragma warning(disable:4996)

to disable the warning, then

#pragma warning(default:4996)

to reset it. Use before, after main method, respectively.

Alternately, try a later Microsoft CRT, or an alternate CRT.

Also, you can use scanf_s instead:
http://msdn.microsoft.com/en-us/library/w40768et(VS.80).aspx
0
How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

 

Author Comment

by:Noo2this
ID: 22693717
Thejaka,
I used scanf_s and it gave me access violations.  I'm new to this visual studio so where exactly do I put the #pragma warning(disable:4996) in my program?
0
 
LVL 8

Expert Comment

by:Thejaka
ID: 22693953
The access violations may have been caused by your compile/link options. Try dynamically linking to CRT by selecting "Multithreaded DLL" build option and linking with msvcp, msvcrt libraries.

For the other, try like this:

#pragma warning(disable:4996)
int main(void)
{
  // Some code...
}
#pragma warning(default:4996)

Open in new window

0
 
LVL 8

Accepted Solution

by:
Thejaka earned 120 total points
ID: 22693974
Regarding the access violation:

In case you didn't check the msdn link, note the following excerpt:

==========

Unlike scanf and wscanf, scanf_s and wscanf_s require the buffer size to be specified for all input parameters of type c, C, s, S, or [. The buffer size is passed as an additional parameter immediately following the pointer to the buffer or variable. For example, if reading a string, the buffer size for that string is passed as follows:

char s[10];

scanf_s("%9s", s, 10);

The buffer size includes the terminating null. A width specification field may be used to ensure that the token read in will fit into the buffer. If no width specification field is used, and the token read is too big to fit in the buffer, nothing will be written to that buffer.

==========

Your line of code could be written as follows:

scanf_s(" %c%c%c", &first, 1, &second, 1, &third, 1);

Open in new window

0
 

Author Closing Comment

by:Noo2this
ID: 31505250
Thejaka, thanks.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let’s list some of the technologies that enable smooth teleworking. 
In this article I discuss my selections of the Top Four free Outlook OST File Viewers available. Open, view and read even damaged OST files by using these tools. They all provide a clear preview of all data such as emails, notes, tasks, calendars, e…
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question