Skip to content

Instantly share code, notes, and snippets.

@prophile
Created September 21, 2009 23:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prophile/190624 to your computer and use it in GitHub Desktop.
Save prophile/190624 to your computer and use it in GitHub Desktop.
void ScanLine ( char* pointer, unsigned long maxlen )
{
#ifdef USE_FGETS
fgets(pointer, maxlen, stdin);
CleanString(pointer, pointer);
#else
char ch;
unsigned long len = 0;
maxlen--; // adjust for space so we can fit a \n in there
while (scanf("%c", &ch) && ch != '\n')
{
if (ch >= 'a' && ch <= 'z')
*pointer++ = ch;
else if (ch >= 'A' && ch <= 'Z')
*pointer++ = (ch - 'A' + 'a');
len++;
if (len == maxlen)
break;
}
*pointer = '\0';
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment