do while

Warning 2 warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. (there are 6 of this)



#define _CRT_SECURE_NO_WARNING_S
#include <stdio.h>

void main ()
{
printf("\n");
printf("1. Harta (Debit)\n");
printf("2. Utang (Kredit)\n");
printf("3. Modal (Kredit)\n");
printf("4. Pendapatan (Kredit)\n");
printf("5. Beban (Debit)\n");
printf("6. Stop\n");


int debit,kredit,harta=0,utang=0,modal=0,pendapatan=0,beban=0,tharta=0,tutang=0,tmodal=0,tpendapatan=0,tbeban=0;
char input;
do
{
fflush(stdin);
scanf("%c",&input);
if(input == '1')
{
scanf("%d",&harta);
tharta+=harta;
}
else if(input == '2' || input == 'b')
{
scanf("%d",&utang);
tutang+=utang;
}
else if(input == '3' || input == 'c')
{
scanf("%d",&modal);
tmodal+=modal;
}
else if(input == '4' || input == 'd')
{
scanf("%d",&pendapatan);
tpendapatan+=pendapatan;
}
else if(input == '5' || input == 'e')
{
scanf("%d",&beban);
tbeban+=beban;
}
}
while(input== '1','2','3','4','5');

printf("Harta: %i\n",tharta);
printf("Utang: %i\n",tutang);
printf("Modal: %i\n",tmodal);
printf("Pendapatan: %i\n",tpendapatan);
printf("Beban: %i\n",tbeban);
debit = tharta+tbeban;
kredit = tutang+tmodal+tpendapatan;
printf("----------------------\n");
printf("Debit: %i\n",debit);
printf("Kredit: %i\n",kredit);
}
That's because you're using scanf, which is a C standard library function. A few years ago, Mikrosoft went krazy and created "secure" versions of a lot of the string handling functions amongst other things. That's what the "_s" in scanf_s stands for - "secure". The warning is to get you to use the scanf_s instead of scanf.

If you're sure of yourself, follow the suggestion and use the flag _CRT_SECURE_NO_WARNINGS when compiling to get rid of the warnings.

I've come up against this particular thing recently, while trying to port code from a Windoze programmer using VS, to Linux and VxWorks. These "_s" functions are all over the place. No doubt they're very safe, and if you don't care about portability (and why should you), then by all means use them.

Carefully check the VS documentation though, these functions tend to add an extra argument, and sometimes there's a posix version of the function that matches the types and number of arguments but not their order.
No doubt they're very safe
They are actually only slightly safer than common ones (they help with less common category of mistakes).
I see my attempt at sarcasm failed miserably...
When posting code, please enclose it in code tags. Highlight the code and click the "<>" button on the right of the edit window.

If you can get past the scanf(), the bug in your code is this:
while(input== '1','2','3','4','5')
which is equivalent to while ('5') which is always true. Look up the comma operator if you don't understand why. Do this instead:
while (input >= '1' && input <= '5')
Topic archived. No new replies allowed.