0

c programming in eclipse

I was doing c program in eclipse, first printf function is not showing in console, after I entered 2 values it is showing 2 printf out in same line, how to clear this problem

#include <stdio.h>
#include <stdlib.h>

int main(void) {

    int a,b,c;

    printf("enter two  numbers");

    scanf("%d%d",&a,&b);

    c=a+b;

    printf("total is %d",c);

    return EXIT_SUCCESS;
}

This is my code

anastaciu
  • 23,467
  • 7
  • 28
  • 53

1 Answers1

0

the problem seems to be that the print isn't flushed to the terminal. when you use printf you actually are writing to a buffer that will be flushed to the terminal after one of the following:

  1. the buffer is full
  2. enough time has passed
  3. you ended your print with '\n'
  4. you give a flush command

I recommend just finishing your print with the '\n'

printf("enter two  numbers\n");
robb218
  • 23
  • 4
  • i tried adding '\n' now the output is showing similar but a slight diffrence : -enter two numbers -answer is 30 before it was in the same line now it is in 2 lines – Younuz B N Jul 23 '22 at 16:10