i am trying to write a program that counts the number of times that a character appears in an array
the code reads:
Code:
/********************************************************
* *
* FILE: ch8_ex3.c *
* CREATED: 8/8/07 *
* BY: bpf *
* *
* this program will run a function that counts the *
* number of times that some character appears in a *
* array. the function will be recursive *
* *
********************************************************/
#include<stdio.h>
#include<string.h>
int appear; /* number of appearances */
main()
{
char num_line[100]; /* variable for number input line */
char num_in; /* variable for pratical number */
char array[100]; /* variable for main fuction's array input */
int length; /* variable for main function's length input */
/* input number: */
(void)printf("number! ");
(void)fgets(num_line, sizeof(num_line), stdin);
(void)sscanf(num_line, "%c", &num_in); /* make "number" a single character */
/* input array: */
(void)printf("array! ");
(void)fgets(array, sizeof(array), stdin);
/* length = length of array */
length = strlen(array);
/* run count function */
(void)count(num_in, array, length);
/* print appear value */
(void)printf("the number appears %d times\n", appear);
return(0);
}
/********************************************************
* *
* FUNCTION: counts the number of times that some *
* character appears in a array *
* PARAMETERS: *
* number - the number being detected in the array *
* array - the array being considered *
* length - the length of the array *
* *
* RETURN: no error (0) *
* *
********************************************************/
int count(char number, char array[], int length)
{
int index; /* index for array */
appear = 0;
/* count the appearences */
for(index = 0; index < length; index++)
{
if(array[index] == number)
appear++;
}
return(0);
}
when i try to compile this in the terminal, the debugger tells me:
ch8_ex3.c:60: error: conflicting types for 'count'
ch8_ex3.c:60: note: an argument type that has a default promotion can't match an empty parameter name list declaration
ch8_ex3.c:38: error: previous implicit declaration of 'count' was here
i've tried changing around the type of variable i declare the count function as but it does not change