简体   繁体   中英

C Program will not continue after scanf function is executed

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM