0
我想在另一个字符数组中找到一个字符串。我试图比较它字符由charcter。但我无法访问个人角色,我需要一些帮助。字符串的位置 - 从指针数组访问单个字符串
代码
#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;
}
谢谢您的帮助。我从上周开始用C语言学习编程。
'而(计数<= LEN){'应该是'while(count
amdixon