View Single Post
Old 04-02-2005, 02:37 PM   #3 (permalink)
destin
Code Monkey
 
Join Date: Mar 2005
Location: NJ
Posts: 41
destin is on a distinguished road
Oh, thanks. I made my own little program out of this..:
Code:
#include <stdio.h>
#include <conio.h>

int count_char(char* str, char needle);

int main()
{
  char *line, letter;
  
  printf("Count what letter? ");
  letter=getche();
  printf("\r\nIn what string? ");
  gets(line);
  printf("You typed '%c' %d times.", letter, count_char(line, letter));
  return 0;
}

int count_char(char* str, char needle)
{
  int count = 0;
  while(*str)
  {
    if(*str == needle)
      count++;
    str++;
  }
  return count;
}
But i dont understand the count_char() function .. would you mind explaining it?
destin is offline   Reply With Quote