2014-02-23 3 views
-1

프로필을 편집하기위한 코드입니다. 그것이해야 할 일은 이전에 사용자가 입력 한 레코드를 편집하는 것입니다. 아무 것도 편집하지 않고 바로 정보를 입력하면 레코드를 찾을 수 없습니다. 누구든지이 문제를 식별 할 수 있습니까 ?? 문제는 편집 중이지만 나머지 코드도 언급했습니다. 목록을 반복하는 동안 루프 내에서 Sorry record not found!!를 인쇄로연결된 목록의 프로필 편집

struct employee { 
    char code[6]; 
    char name[15]; 
    char nationality[15]; 
    char gender[8]; 
    struct employee *newPtr;  
} *start, *curr; 

void append() { 
    curr = start; 
    if(start == NULL) {  
     start = curr = (struct employee*)malloc(sizeof(struct employee)); 
     employee_entry(); 
     curr->newPtr = NULL; 
     printf("\n\nFirst Node Added!!!"); 
     return;   
    } 
    while(curr->newPtr) 
     curr = curr->newPtr; 
    curr->newPtr = (struct employee *)malloc(sizeof(struct employee)); 
    curr = curr->newPtr; 
    employee_entry(); 
    curr->newPtr = NULL; 
    printf("A new Node has been added to the list!!!"); 
} 

void edit() { 
    char name[8];  
    curr = start;  
    printf("\nEnter name to modify:"); 
    gets_s(name);  
    while(curr) { 
     if(strcmp(curr->name, name) == 0) { 
      employee_entry(); 
      printf("\n\n\t\t The required data has been edited!!!"); 
      return; 
     } 
     curr = curr->newPtr; // current pointer points to the next file 
     fprintf(stderr, "\n\n\t\tSorry record not found!!"); 
    } 
} 
+1

'시작'이란 무엇입니까? 언제, 어떻게 할당 되었습니까? 질문을 수정하고 개선하여 더 많은 코드를 표시하십시오! –

+0

@basile 여기 코드의 나머지 부분이 있습니다. – Bonzi

답변

0

코드는 당신을 오해. 모든 목록 항목을 확인한 후에 항목을 찾을 수 없다는 결론 만 내릴 수 있으므로 루프 외부의 오류 메시지를 가져 오십시오.

while(curr) { 
    if(strcmp(curr->name, name) == 0) { 
     employee_entry(); 
     printf("\n\n\t\t The required data has been edited!!!"); 
     return; 
    } 
    curr = curr->newPtr; // current pointer points to the next file 
    /// don't print here error message 
} 
//print here 
fprintf(stderr, "\n\n\t\tSorry record not found!!");