Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

"c" compiler error message...

demet8demet8 Posts: 2Member
why is the compiler giving me an error of undefined reference to
'findChar' ? also how can I display all the characters entered?

Here's my code:

#include
#include


#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 :
");

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

printf("Search a character :
");

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

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

int findChar(char array[], char c)
{
int i, j;
for(i = 0; array[i] != ''; 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] != ''; i++)
{
if(array[i] == c)
{
j++;
}
}
return j;
}

Sign In or Register to comment.