1

So, i just want to know how to deal with this, the code doesnt have a purpose besides testing. why does the the enter i press go to the getchar()command? or is that the case to begin with? i assume it is. here is the code

#include<stdio.h>

int main(){
    int x,y,z;

    printf("Enter two nums\n");
    scanf("%d %d", &x, &y);
    z=x/y;

    printf("%d is answ\n", z);
    puts("Press enter to exit");
    
    getchar();
    return 0;

}
  • 1
    When you enter the input for the numbers (`x` and `y`), you press the `Enter` key right? That will be added into the input buffer for your `getchar` to read. – Some programmer dude Nov 06 '20 at 09:14
  • Hi , in most of cases we using getchar() before return 0 as last step in program just for making console visible . but real usage of getchar() just getting character from user & deal with it :) – 0x00001F Nov 06 '20 at 09:17

0 Answers0