I wrote a code in C to print the id number (could be combination of both numbers and letters) of the employee. The compiler takes the id number as an input but it is printing nothing. At first, I use 'printf' but it is not working so then I googled to end up with that the output is sometimes buffered for performance reasons in many systems. I got many possible answers in some following threads-
- simple c program not printing output
- Why does printf not flush after the call unless a newline is in the format string?
- printf not printing on console
However, I tried all of the possibilities (being a beginner, implementation can be wrong), but none worked out for me [given as comments]. I have the code like following. Any help is appreciated.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int* ptr;
int m;
char n;
printf("Id number of employee 1:\n");
printf("Enter your id number length\n");
scanf("%d", &m);
printf("%d\n", m);
ptr = (int*) malloc (m *sizeof(int));
printf("Enter your id number:\n");
scanf("%s", &n);
// fflush( stdout );
// fprintf(stderr, "The id number of emploee 1 is %s", n);
// setbuf(stdout, NULL);
// setvbuf(stdout, NULL, _IONBF, 0);
// setvbuf (stdout, NULL, _IONBF, BUFSIZ);
// printf("The id number of employee 1 is %s\n", n);
printf("The id number of employee 1 is %s", n);
return 0;
}