질문 : 최대 6 쌍의 이름과 연령대를 두 개의 개별 배열로 읽고 선형 검색을 사용하여 대상 이름을 찾고 그 사람의 나이를 인쇄하십시오.선형 검색 구현
#include <stdio.h>
#define ASIZE 20
#define RECSIZE 6
struct record {
char name[ASIZE];
int age[ASIZE];
};
struct record na[RECSIZE];
int linearSearch(struct record *a, char *find)
{
int x;
for(x=0; x<RECSIZE; x++)
{
// if(na[x].name==find[x])
if(a->name[x]==find[x])
{
return x;
}
}
return -1;
}
int main()
{
int i;
for (i=0; i<RECSIZE; i++)
{
printf("Enter name: ");
scanf("%s",na[i].name);
printf("Enter age: ");
scanf("%i",&na[i].age);
}
printf("Enter the Search name: ");
char temp[ASIZE];
scanf("%s",temp[ASIZE]);
int result;
result=linearSearch(&na, &temp[]);
printf("%i", result);
return 0;
}
도와주세요 .. 내가 함수로 배열을 전달하는 방법에 대한 모르겠습니다 ..
나는 많은 오류를 얻고있다 : 두 배열은 이름과 나이라고합니다. = 결과 linearSearch (& NA, & 온도 []);
오류가입니다
이 우리에게 오류를 표시합니다. – Adam
그래서 우리가 뭘하고 싶니? 오류를 표시하지 않습니다. 코드를 보면서 C 책을 얻거나 네트워크에서 자습서를 찾아서 읽는 것이 좋습니다. – OldProgrammer
result = linearSearch (& na []. name, & na []. age, & temp []); 토큰 – user3541302