Hi,
I am writing a program that reads in from stdin and writes into a string.
I enter few characters and hit enter expectign that the final printf statement would output a string coming all the characters. But I always get junk printed out. I tried to malloc(10) for *sb and tried to print again. I got blank string. Could someone please point out what is going wrong ? Is it a problem with using getchar() ?Code:int main() { int file; char *sb, c; while((c = getchar()) != '\n'){ printf("Entered in\n"); if (isalnum(c)) *sb++ = c; printf(" The String: %s\n" , sb); } }
Please suggest me a way to get series of characters to be copied as a single string to *sb
-Jeck