Help, my program is to search a alphabet in a list of string, and return the postition, if not found return with -1.
What's is doing wrong of my code?
ie. should return '7' of 'h'.
thk a alot.
Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int firstIndex(char* str, char aChar) {
int i,length;
length=100;
for (i=0;i>=length ;i++ )
if (str[i]==aChar)
return i;
else
return -1; /* If can't found */
}
void main() {
char aChar='h';
int index;
char* str[99]={"a","b","c","d","e","f","g","h","i","j","k","l","m"};
index=firstIndex(str,aChar);
printf("The char is in position %d\n",index);
getchar();
}