Right, I sometimes forget about the return value when I'm experimenting with simple code like this.
I found some errors, I declared x twice for some reason. I modified the code:
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char *string=(char*)malloc(sizeof(char)*100);
char x;
x=getchar();
while(x!='\n')
{
*string=x;
string=string+1;
x=getchar();
}
*string='\0';
printf("%s",string);
return 0;
}
Now the problem is, at the end of the first getchar() the program just returns 0 regardless of which character I enter.