Why is scanf in a for loop not working in visual studio. But it works dev c++?
NickName:Anjana Indunil Ask DateTime:2022-12-10T13:46:36

Why is scanf in a for loop not working in visual studio. But it works dev c++?

visual studio erro

dev c++

this code is working in dev c++, ut not working visual studio. erro is

Error C4996 'scanf': This function or variable may be unsafe. Consider using scanf_s instead.

code is...

#include<stdio.h>

int main() {

    int arr[5] = { 0 };
    int i = 0;

    printf("Enter the number :");
    for (i = 0; i < 5; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;

Copyright Notice:Content Author:「Anjana Indunil」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/74750685/why-is-scanf-in-a-for-loop-not-working-in-visual-studio-but-it-works-dev-c

More about “Why is scanf in a for loop not working in visual studio. But it works dev c++?” related questions

Why is scanf in a for loop not working in visual studio. But it works dev c++?

visual studio erro dev c++ this code is working in dev c++, ut not working visual studio. erro is Error C4996 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. c...

Show Detail

visual studio wont scanf

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? ano...

Show Detail

Why is %hd necessary in scanf?

I created a very simple progam whith a menu, that take a value, then memorize it into the local variable value, and finally with the second option the progam prints the value. my question is: Why...

Show Detail

What are the mechanics of scanf() in C

So I started learning C today, and as an exercise I was told to write a program that asks the user for numbers until they type a 0, then adds the even ones and the odd ones together. Here it is: #

Show Detail

Why is this simple c scanf code causing infinite loop?

first question on stack overflow for me, let's see how well this goes! I can't understand why this simple piece of c code is causing an infinite loop. #include &lt;stdio.h&gt; #include &lt;stdlib...

Show Detail

How format specifiers works with scanf in loop in C?

This code works correctly : int main() { int i,n=2; char str[50]; for (i = 0; i &lt; n; i++) { puts(&quot;Enter a name&quot;); scanf(&quot;%[^\n]%*c&quot;,

Show Detail

scanf causing infinite loop in C

I am relatively new to C, but I have been programming for a few years now. I am writing a program for a college class, and I am confused why the scanf function below is not called, resulting in an

Show Detail

Working of scanf under for loop

I have a question about working of for loop in C. Please have a look at the following code: #include&lt;stdio.h&gt; void main() { int ar[10],i; printf("Enter 10 numbers:"); for(i=0;i&...

Show Detail

Not sure why while loop works different when using scanf

I'm new in the journey of learning C and to my knowledge, I knew that while loop would run forever if someone gives condition such as while (1 == 1) it would become a forever loop. But While reading

Show Detail

Why does this scanf in a while loop work?

I can't understand why this does exactly what I want. The part where I used two scanf's in the loop confuses me. I compiled it using devcpp. #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; int...

Show Detail