c언어 오류 해결이 어렵습니다.

oeo0750의 이미지

자료구조를 공부하면서
정수 리스트를 구성하고, 그 리스트 안에서 정수 num을 찾는 함수를 작성하는데,
리스트에 num이 있으면 함수가 num을 포함한 노드의 포인터를 반환하고, 없으면 null을 반환하는 함수입니다.

이 함수를 이용해서 리스트에서 num이란 숫자를 가진 노드를 삭제하는 프로그램을 작성하였습니다.
한 번 봐주시면 감사하겠습니다!

#include <stdio.h>
#include <stdlib.h> 
 
typedef struct listNode *listPointer;
typedef struct {
    int data;
    listPointer link;
}listNode;
 
listPointer search(listPointer ptr, int key)
{  /* determine if key is in the list */
  listPointer temp;
  for (temp = ptr; temp; temp = temp->link) 
        if (temp->item.key == key) return temp;
  return NULL;
}
 
listPointer Deletelist(listPointer ptr, int searchNum, int *found)
{/* search for an  element, delete it if it is in the list
   The pointer to the head of the list is returned in the function name,
   the value of found will be 1, if the entry was deleted, and 0
   otherwise */
 
    listPointer position,temp;
    position = search(ptr,searchNum, found);
    if (*found) {
      if (!position) {
 /* entry was  found at the head of the list, delete
      the current head pointer, and return the link field
      as the new pointer to the head of the list */
 
    	   temp = ptr->link;
    	   free(ptr);
    	   return temp;
       }
       else {
 
 /* entry was not at the head of the list, change the
       link pointers and free the storage */
 
      	   temp = position->link;
      	   position->link =  temp->link;
      	   free(temp);
      	   return ptr;
	}
      }
      else
/* item was not found in the list, return the pointer to
	 the head of the list */
 
      return ptr;
}
 
 
int main (void)
{
int num, found;
listPointer ptr;
 
printf("삭제하고 싶은 숫자를 입력하세요: ");
scanf("%d",&num);
ptr = Deletelist(ptr,num,&found);
if (found)
		  printf("입력한 숫자가 삭제되었습니다.\n");
else
		  printf("입력한 숫자가 리스트에 없습니다.\n");
 
}
세벌의 이미지

제목을 보면 프로그램에 에러가 난다는 거 같은데 본문에는 에러메시지에 대한 얘기는 안 보이네요?
어떤 에러가 나나요?

https://wiki.kldp.org/wiki.php/DocbookSgml/Beginner_QA-KLDP#AEN70
참고하여 질문하시면 답을 얻는데 도움될 겁니다.

oeo0750의 이미지

감사합니다. 디버그 했을 때 현재 에러는 첨부한 그림과 같이 뜨는데요, 한 두개가 아니기도 하고 ㅠㅠㅠ
프로그램 전체적으로 문제가 있나 궁금하네요.

댓글 첨부 파일: 
첨부파일 크기
Image icon 에러.JPG174.6 KB
세벌의 이미지

한꺼번에 에러를 다 잡긴 쉽지 않을 겁니다. 하나씩 하나씩 잡아보셔요.
일단 힌트 하나만 드립니다.

함수 정의는

listPointer search(listPointer ptr, int key)
이렇게 변수 2개를 받는 걸로 만들고
할수 호출은
position = search(ptr,searchNum, found);
이렇게 변수 3개를 받으면 변수 짝이 안 맞죠.

덧.
에러메시지를 화면캡처해서 이미지 첨부하는 것 보다는, 텍스트 파일로 저장해야 답변 받기 좋습니다.

익명 사용자의 이미지

답변을 달아 드리고 싶음데

올리신 코드는 뭔가 많이 빠져 있는게 많은 듯 하네요

oeo0750의 이미지

그렇죠? 제가 아직 c언어가 수준이 높지 않아서 배운걸로 어찌저찌 써봤는데 많이 부실한 듯 하네요 ㅠㅠ 그런데 어떻게 보강해야 할지 모르겠어서 글을 올려보았습니다 ㅠㅠ

익명 사용자의 이미지

어떤 문서를 보고 Copy & Paste 하신지는 모르겠지만

구글에 "c linked list" 또는 "c 연결리스트"만 검색해도 한글로 잘 설명된 문서들이 많습니다.

한번 차근차근 타이핑 해가면 해보시기 바랍니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.