reads a line of text into a char array q and returns its length: - C Function

C examples for Function:Utility Function

Description

reads a line of text into a char array q and returns its length:

int getline(char q[], int limit)
{
 int ch, j;
 for(j=0; j<limit-1 && (ch=getchar())!=EOF && ch!='\n'; ++j)
   q[j] = ch;
 if(ch == '\n'){
   q[j] = ch;
   ++j;
 }
 q[j] = '\0';
 return j;
}

Related Tutorials