I know that multiple functions are already available. However, I thought of writing my own because I wanted to learn the logic (and also because I thought there wasn't enough confusion :P). Please review the function I wrote and suggest me efficient changes.
Without further ado, here I go:
scan(string,size)
char** string;
size_t size;
{
string[0]=(char*)malloc(sizeof(char));
char keystroke=' ';
while((keystroke=getc(stdin))!='\n') {
string[0][size++]=keystroke;
string[0]=(char*)realloc(string[0],size+1);
}
string[0][size]='\0';
return size;
}