-1

I have a simple program in C that I am using to learn how to use scanf() for future school projects. When I execute the program through the linux terminal I have to use the end command to end the program and then it will give me the value that I input. Is there something wrong with my code?

Problem: After scanf function is executed, the printf function afterward will not be executed until I use the end terminal command.

code

#include<stdio.h>

int main(void)
   {
       int a = 0;//declaring int a
       printf("Type a value in: ");//asks for value
       scanf("%d\n" , &a);//scans use input assigns value to a
       printf("Your value is %d \n" , a);//prints value of a

       return 0;//returns value to end program
   }//end main
amdixon
  • 3,814
  • 8
  • 25
  • 34
JBeeman
  • 3
  • 1
  • 3

1 Answers1

1

Get rid of the "\n" in the scanf format string.

See Using "\n" in scanf() in C

Community
  • 1
  • 1
Michael Albers
  • 3,721
  • 3
  • 21
  • 32
  • Thanks! I think I understand what is happening. I can ask one of my professors about it later to get a better understanding. – JBeeman Sep 13 '15 at 02:06