-6

私はリストを持っています、そして私は人々の名前を比較するこのリストからレジスターを削除したいと思います。関数removeは次のとおりです。

void remove(char name[]){
  if (pBegin!=NULL){
    Nodo *pcopy;
    if (!strcmp(name,pBegin->person.name)){
      pcopy=pBegin;
      pBegin=pBegin->pNext;
      printf("REMOVED!\n");
      free(pcopy);
    }
    else{
      Nodo *pCurrent=pBegin;
      Nodo *pPrevious=NULL;
      while ((strcmp(name,pCurrent->person.name)) && (pCurrent!=NULL)){  // here is probably the error
        pPrevious=pCurrent;
        pCurrent=pCurrent->pNext;
      }
      if (pBegin==NULL)
        printf("The name was not found!\n");
      else{
        pPrevious->pNext=pCurrent->pNext;
        printf("REMOVED!\n");
        free(pCurrent);
      }
    }
  }
  else
    printf("empty list!\n");
}

大きな投稿と視覚的に醜いことをお詫びします。これは私の最初の投稿であり、Cは初めてで、すべてを試しましたが、このエラーを解決できません。

4

1 に答える 1

1

strcmpで使用した後、pCurrent!=NULLをテストするには遅すぎます。

   while (pCurrent!=NULL && strcmp(name,pCurrent->person.name)){ // test names are different
于 2013-03-24T23:40:59.957 に答える