Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- char name[27];
- int ReadLine( char* buffer , int maxLen )
- {
- int len;
- //read up to maxlen+1 chars (including the '\n')
- fgets(buffer,maxLen+1,stdin);
- len = strlen(buffer);
- //there is a '\n' at the end?
- if(buffer[len-1] == '\n')
- { //yes... so <= maxlen
- (buffer[len-1] = '\0'; //turn \n into ending...
- }
- else //no... so > maxlen (will return maxlen+1 as size)
- {
- // read the rest of the line...
- while ( !strchr( buffer , '\n') ) { fgets(buffer,maxLen+1,stdin); }
- }
- return len;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement