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