Skip to content

Instantly share code, notes, and snippets.

@daqing
Created February 21, 2009 08:11
Show Gist options
  • Save daqing/67951 to your computer and use it in GitHub Desktop.
Save daqing/67951 to your computer and use it in GitHub Desktop.
#include <stdio.h>
void countNewLine(char, int *);
int main(void)
{
int count = 0;
countNewLine(getchar(), &count);
printf("Your input has %d newline%c\n", count, (count > 1) ? 's' : ' ');
return 1;
}
void countNewLine(char c, int *count)
{
if (c == EOF)
return;
if (c == '\n')
++(*count);
countNewLine(getchar(), count);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment