Quantcast
Channel: Programmers Heaven Forums RSS Feed
Viewing all articles
Browse latest Browse all 2703

"c" compiler error message...

$
0
0
why is the compiler giving me an error of undefined reference to
'findChar' ?? also how can I display the character entered. Any ideas would be appreciated. Thanks.

#include <stdio.h>
#include <stdlib.h>


#define SIZE 100

int findChar(char array[], char c);
int findCount(char array[], int c);

int main()
{
int count;
int position;
int frequency;
char ch, array[SIZE];

printf("Enter a character : \n");

for(count = 0; ((array[count] = getchar()) != '\n'); ++count);
array[count+1] = '\0';

printf("Search a character : \n");

ch = getchar();
position = findchar(array, ch);
frequency = findCount(array, ch);

if(position == -1)
{
printf("Not found! \n");
}
else
{
printf("%c is found in the position of %d", ch, position+1);
printf("The count of %c is %d \n", ch, frequency);
}
system("pause");
return 0;
}

int findChar(char array[], char c)
{
int i, j;
for(i = 0; array[i] != '\0'; i++)
{
if(array[i] == c)
{
return i;
}
}
return -1;
}

int findCount(char array[], int c)
{
int i;
int j = 0;

for(i = 0; array[i] != '\0'; i++)
{
if(array[i] == c)
{
j++;
}
}
return j;
}


Viewing all articles
Browse latest Browse all 2703

Trending Articles