I want to find a string inside another character array. I tried to compare it character by charcter. But I cannot access individual character, I need some help here.
code
#include <stdio.h>
#include "source.h"
int main()
{
char *str[] = {"one","two","three","four"};
int index;
index= locate_string(str, 4, "one");
printf("String one is in the position %d\n", index);
return 0;
}
int locate_string(char **stringArray, int len, char * string)
{
int count = 0;
while(count <= len){
int j = 0;
char *temp = (*stringArray)[count];
while(j < len){
if(temp == string[j]){
j++;
}
}
if(j == len-1){
return count-j;
}
}
return -1;
}
Thanks, for the help. I'm learning programming in C from last week.
while(count <= len){should bewhile(count < len){. should use strcmp to compare strings