Home > Mobile >  scanf Function doesn't work in vscode for some reason, any tip?
scanf Function doesn't work in vscode for some reason, any tip?

Time:12-20

I got used to printf and variables in C, then I started to use the scanf function, here's the code (shamelessly stolen from fresh2refresh.com)

#include <stdio.h>
int main()
{
   char ch;
   char str[100];
   printf("Enter any character \n");
   scanf("%c", &ch);
   printf("Entered character is %c \n", ch);
   printf("Enter any string ( upto 100 character ) \n");
   scanf("%s", &str);
   printf("Entered string is %s \n", str);
}

Except that it doesn't run, neither on the vscode output or cmd. it doesn't even print the "Enter any character" from line 5, it show that the code is running, but doesn't even accept inputs (and will only halt once I click the Stop Code Run button)

any tips?

CodePudding user response:

The line

  scanf("%s", &str);

Is incorrect - it should be

  scanf("           
  • Related