Hello,
I am currently new to both this board and to C programming. What I am attempting to do, is to compare a character to another one.
This is done by:
Code:
char vowels[] = "aeiouyæøå";
int isVowel(char c)
{
int i;
for(i = 0; i < strlen(vowels); i++) if(strcmp(tolower(c), vowels[i]) == 0) return 1;
return 0;
}
// Several other irrelevant lines of code
// I have some lines of a song saved in char *lines[NO_LINES]
// where NO_LINES is defined to 4.
// The call of isVowel from the function rem:
int rem(void)
{
int i;
for(i = 0; i < NO_LINES; i++)
{
int j;
for(j = 0; j < strlen(lines[i]); j++)
{
if(isVowel((char)lines[i][j]) == 0) printf("%c", lines[i][j]);
}
}
return 1;
}
I try merrily to compile this, and I get some warnings:
Code:
$ cc o1.c
o1.c: In function 'isVowel':
o1.c:17: warning: passing argument 1 of 'strcmp' makes pointer from integer without a cast
o1.c:17: warning: passing argument 2 of 'strcmp' makes pointer from integer without a cast
And when I try to run the program, I get:
Code:
$ ./a.out remove tresmaa.txt
Bus error
remove is an argument to start rem(), and lines[] is filled with 4 lines from before rem()'s call. I have tried to debug this, and it is the strcmp(tolower(c), vowels[i]) call that causes the problem. I have ensured that I have included all necessary headers, but I cannot see why I get this bus error. Thus I would be more than happy if I could get some help from you.
Thanks in advance and best regards,
Thuz