Home > Back-end >  # # amateur who help questions about the string output
# # amateur who help questions about the string output

Time:09-18

Write a function that about read string, the function prototype is as follows:
Char * l_gets (char [] st, int n)
{
Char * ret_val;
int i=0;

Ret_val=st;

While (i{
St [I]=getc (stdin);
i++;
}
If (st [I]=='\ n')
St [I]='\ 0';
The else
While (getchar ()! )
='\ n'continue;

Return ret_val;
}
Compiled with puts output, n - 1 characters after the garbled words, original intention is to create a function, function reads n characters of the screen, and stored in a string, don't want to use the fgets, so use getc, but output always has a problem, if it weren't for the code, or more than n characters in the buffer zone under the influence of a function,
Consult a great god, and this is how to return a responsibility?
  • Related