I'm trying to write C code where it takes in integer inputs, and prints them, unless the newline character ('\n') is entered.
But it never returns the value that I enter. If I enter 6, I expect it to print 6 but it gives me 54. In fact whatever number I expect, it gives me 48+(my number). Please help!
Here's my code:
#include <stdio.h>
int main(int argc, char *argv[])
{
int counter = 0;
int num;
while (counter <=1)
{
num = getchar();
if (num == '\n')
{
break;
}
counter+=1;
printf("%d", num);
}
return 0;
}