I'm trying to create a function that get a string, taking char by char:
char * GetString (int dim) // dim is the size of the string
{
char c, *S;
int i = 0;
S = (char*)malloc(dim*(sizeof(char));
while ((c=getchar() != '\n') && (i < dim) && (c != EOF))
{
S[i] = c;
i++;
}
S[i] = '/0';
return S;
}
The problem is when i try to use a "printf" in this function, trying to see if the input was taken correctly, it shows me strange characters, not the ones i inserted. I don't know what i'm missing.
Thanks very much.