0

so I started programming in c on visual studio. (i must use vs)

while my instructer can use scanf on vs, i cant (must use scanf_s).

can anyone tell me why? or what other diffrences could be?

another thing is that my instructer ran this (below) code fine, but my computer compile it good but the output is messed up.

#include <stdio.h>
void main()

{

    int x, y;

    char z;

    printf("put expression");

    scanf_s("%d%c%d", &x, &z, &y);

    printf("%d%c%d", x, z, y);

}

*if i only scan int and a char (without the last int) it works fine. (scanf_s("%d%c"))

  • the goal is to input 2+2 and know i can save each of them in diffrent veriables.

why dose my vs act diffrent that my instructer vs? (same code)

how can i fix it? and if i cant how can i know what other diffrences we might have?

thank you guys and have a good weekend!

UnholySheep
  • 3,125
  • 4
  • 20
  • 23
guyguy
  • 1
  • What do you mean by *"output is messed up"*? Please provide sample input and output – UnholySheep Apr 24 '20 at 12:06
  • As for `scanf` vs `scanf_s` in VS refer to https://stackoverflow.com/questions/30577519/error-c4996-scanf-this-function-or-variable-may-be-unsafe-in-c-programming – UnholySheep Apr 24 '20 at 12:07

1 Answers1

1

You should use _CRT_SECURE_NO_WARNINGS go to project projectname properties c/c++ preprocessor you should see preprocessor definition add it there

BerkanG
  • 13
  • 3