구조체 항목을 삭제 한 다음 realloc
을 사용하여 메모리를 확보하려고합니다. 내 구조는구조체 항목을 삭제하고 realloc을 사용하여 메모리를 확보하는 방법
typedef struct person {
char fname[20];
char lname[20];
int number[10];
}person;
임 입력 된 항목
void delInfo(int*,person*);
삭제 기능이 작동하도록되어 방법을 삭제하는 함수를 사용하고 다음, 그 후 다시 모든 레코드를 이동, 상기 엔트리의 위치를 마지막으로 해방하는 것입니다 realloc
으로 녹음하십시오. 는 코드는 지금까지 지금까지 내가 처음이자 마지막 이름의 일치 검색,하지만 난 모든 항목을 이동하면 어떻게되는지 잘 모릅니다 수있는이
void delInfo(int *num_entries,person*contacts){
char delfirst[20];
char dellast[20];
printf("\n First Name: ");
scanf("%s",delfirst);
printf(" Last Name: ");
scanf("%s",dellast);
int i=0;
for (i=0; i<*num_entries;i++){
if (delfirst==contacts[i].fname && dellast==contacts[i].lname){
}
}
}
처럼 보인다 "아래 하나." 항목을 일치하는 것은 내가 할 경우
int c;
for (c=i+1;c<*num_entries;c++){
contacts[i].fname=contacts[c].fname;
contacts[i].lname=contacts[c].lname;
contacts[i].number=contacts[c].number;
}
contacts=(person*)realloc(contacts,sizeof(contacts)*(num_entries-1));
같은 연락처 [I] 일 경우 것과 나는 할 수 realloc
그들은 그냥 삭제할 항목을 "덮어 쓰기"않습니다 내가 삭제에 계획 한 이후의 모든 항목,에 구조 배열을 줄이고 본질적으로 메모리를 해제 하시겠습니까?