1
[Error] 'scanf_s' was not declared in this scope

I'm new here and i don't know much about programming We use this type of programming at University. we add this before main body /*#include ,#pragma warning(disable:4996)

#include<stdio.h>
int main()
{

int _a;
char _b;
printf("Zadaj cislo od 0 do 15: ");
scanf_s("%d",&_a);
asm(".intel_syntax noprefix \n"
 "mov eax, _a \n"
 "mov ecx, 9 \n"
 "cmp eax,ecx \n"
 "jg vacsie \n "                         
 "jl mensie \n"
 "mensie: \n"
     "add eax, '0' \n"
     "jmp end"
 "vacsie: \n"
    "add eax,55 \n"
"end:"
    "mov _b,al"
".att_syntax \n"
);
if (_a<=15 && _a>0)
    printf("v hexa %c \n",_b);
else printf("cislo nieje spravne");
getchar();
return 0;

}
Michael Petch
  • 46,082
  • 8
  • 107
  • 198
  • 3
    `scanf_s` is microsoft extension. Switch to standard `scanf`. – Jester Mar 28 '19 at 19:30
  • 3
    Dev-C++ uses the GCC compiler. It might not have an implementation of `scanf_s` which started out as a VisualC++ extension. Especially considering that Dev-C++ have been lagging behind other IDE's, including providing up-to-date compiler version (`scanf_s` was added to standard C with the C11 standard, which might also need special flags to enable). – Some programmer dude Mar 28 '19 at 19:38
  • 1
    @Someprogrammerdude The compiler does not provide the function; it's the libc that provides it. – fuz Mar 28 '19 at 19:41
  • And why are you using inline assembly? With a good compiler it's actually very unlikely that you're going to be able to create more optimized code than the compiler. What is the problem you try to solve? Have you benchmarked, measure and profiled that your code would be faster than the corresponding C code (built with optimizations enabled)? – Some programmer dude Mar 28 '19 at 19:41
  • 4
    @Someprogrammerdude : Just an extension of your comment. It was added to C11 as an optional feature in Annex K. So even C11 doesn't require it, and Annex K could be removed from future standards. – Michael Petch Mar 28 '19 at 19:47
  • 3
    There are quite a few issues in the inline assembly itself. It seems to have been ported from Microsoft `asm{}` statement. Some of the lines are missing a `\n`, registers are clobbered and the compiler hasn't been told, and GCC documentation explicitly mentions that accessing variables directly inside inline assembly shouldn't be done. Even then if you do try to use them they have to be at global scope (and even then the optimizer can get rid of them if not referenced in the C code) causing them to be undefined. – Michael Petch Mar 28 '19 at 19:50
  • Since this is likely homework, I won't post entirely cleaned up code. There are some lines in assembly that are unneeded; and it could be more efficient. However something that uses constraints and clobbers; has a \n on all the lines that need it can be found here:http://www.capp-sysware.com/misc/stackoverflow/55405492/hex.c . This is only to allow it to correctly run, but there are better ways to do it. As well I think you meant to use `if (_a<=15 && _a>=0)` rather than `if (_a<=15 && _a>0)` – Michael Petch Mar 28 '19 at 20:15

0 Answers0