added string input with scanf()

This commit is contained in:
Sylvain PILLOT 2023-02-18 21:54:57 +01:00
parent 4639a1e9ce
commit f21cc97bb5
1 changed files with 37 additions and 1 deletions

View File

@ -273,7 +273,43 @@ int __scanf(
// read a serie of non whitespace char from the current input stream
// and store in the corresponding arg as a char by reference
/* TODO: */
char *c = (char *) va_arg( *args, char* );
char temp;
if (in->readmaxlength==-1) // read the maximum number of non-whitespace characters
{
for(;;)
{
temp = __scanf_peek( in );
if (!isspace(temp) && temp != EOF)
{
*c = __scanf_in( in );
in->readsofar++;
c++;
}
else break;
}
*c = '\0'; // add the mandatory terminal '\0'
}
else
{
for(int u = 0; u < in->readmaxlength; u++ )
{
temp = __scanf_peek( in );
if (!isspace(temp) && temp != EOF)
{
*c = __scanf_in( in );
in->readsofar++;
c++;
}
else break;
}
*c = '\0';
}
in->readmaxlength=-1;
ret++;
break;
}
}