I'm trying to find out how to read a hyphen from an array. I've got the following set up:
Code:
#include <stdio.h>
int main()
{
char data[5];
int a = 0;
puts("Enter: ");
fgets(data, 5, stdin);
for (;a < 5 ; a++)
{
if (data[a] = '-')
{
printf("A - was found!\n");
}
}
return 0;
}
It doesn't work however. I get the following output:
Code:
pim@zwart:~/C$ ./a-b
Enter:
abcde
A - was found!
A - was found!
A - was found!
A - was found!
A - was found!
Obviously the if statement isn't working properly. I wonder why this is the case tough. It's checking for a characters in a character array.
Anyone has any thoughts on this?
Thank You.