So I have been trying to read input string and then print it by not using neither scanf()
nor printf()
but getchar()
and putchar()
instead.
It seems like the program is stuck in the loop, I'm not able to spot an error.
#include <stdio.h>
void getstring(char *c)
{
char inS[100];
char n;
int i = 0;
while ((n = getchar()) != '\n') {
inS[i] = n;
i++;
}
inS[i] = '\0';
i = 0;
while (inS[i] != '\0') {
putchar(inS[i]);
i++;
}
}
main()
{
char *prompt;
prompt = "Enter a sentence: \n";
getstring(&prompt);
printf("%s", prompt);
}