Hi, I am trying to read a string using the function below.
The problem I have is that I can't write space in my string.
So strings like : "name fullanme" are rejected
and returns only "name".
char *getstring(char *ret, int max)
{
char *ppp, *qqq;
int invalid_characters=0;
//fgets(ret,max,stdin); //it does not work
scanf("%s",ret);
for(ppp = qqq = ret; *ppp; ++ppp){
switch(*ppp){
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case '\n': case '\t': case '.': case ',': case '!':
case '?': case ';': case '$': case '@': case '#':
case '%': case '^': case '(': case ')': case '[':
case ']': case '{': case '}': case '&': case '*': invalid_characters++;
break;
default: *qqq++ = *ppp;
break;
}
}
*qqq = 0;
return((qqq != ret) ? ret : NULL);
}
Could you help me please to correct this ?