0

I am currently doing C programming in the terminal of nano text editor in kali linux 2020.x.
15 minutes ago, I wrote a code which is not working finely. I am mentioning that code.

#include<stdio.h>
int main(){
  int num;
  scanf("%d",&num);
  printf("number is %d",num);
  return 0;
}

I ran it. all things were ok, it compiled also, but when I am trying to enter value and press enter key, the output is blank/no output.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Get_ Maths
  • 103
  • 4
  • 3
    try adding a line feed to your output line. `"number is %d\n"`. Some terminal modes are line wise not character wise. – BitTickler Jan 25 '21 at 06:07
  • thanks , it works. very very thanks bro – Get_ Maths Jan 25 '21 at 06:08
  • you can also use `fflush(stdout)` after printf. – Sam______ Jan 25 '21 at 06:15
  • Note that you should check the return value from `scanf()` before using the value that may not have been assigned successfully. Plan to end all printing operations with a newline; it helps ensure that the output appears timely when sent to a terminal. – Jonathan Leffler Jan 25 '21 at 06:54

1 Answers1

0

I don't know if you have an answer yet, but I gave your question a shot and made this:

int main()
{

    int m_iValue = 0;
    
    scanf( "%i", &m_iValue );

    {
              char m_szBuffer[128]; // Note: We got a BIG buffer boy!
        sprintf( m_szBuffer, "Value: %i \n", m_iValue );

        printf( m_szBuffer );
    }

    return 0;

}

It works perfectly fine; hope it helps!

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278