주소값을 리턴받았을 때 출력방법

chavi55의 이미지

difference(차집합 만드는 함수)에서 주소값c를 리턴받는데 이를 어떻게 main함수에서 출력해야할지 모르겠습니다.
복붙하니까 탭키가 안되네요 죄송합니다.

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
#define maxsize 5
 
typedef struct {
	int nElements;
	int arraySize;
	char **element;
} strset_t;
 
strset_t *createSet(char *element)
{
	strset_t *s = (strset_t *)malloc(sizeof(strset_t));
	s->element = (char **)malloc(sizeof(char *)*maxsize);
 
	s->nElements = 0;
	s->arraySize = maxsize;
 
	return s;
}
 
int addElement(char *x, strset_t *a)
{
	if(a->arraySize == a->nElements)
	{
		a->arraySize = a->arraySize * 2;
		a = realloc(a, a->arraySize);
	}
 
	if(isElement(x, a) == 1)
		return 0;
 
	if(a->element == '\0')
		return 0;
 
	a->element[a->nElements] = (char *)malloc(strlen(x) + 1);
	strcpy(a->element[a->nElements], x);
	a->nElements++;
 
	return 1;
}
 
int removeElement(char *x, strset_t *a)
{
	int value = isElement(x, a);
 
	if(value == -1)
		return 0;
 
	for(int i = value; i < a->nElements - 1; i++)
	{
		free(a->element[i]);
		a->element[i] = a->element[i + 1];
	}
 
	free(a->element[a->nElements - 1]);
	a->nElements--;
} 
 
strset_t *intersection(strset_t *a, strset_t *b)
{
	int cnt = 0, k = 0;
	strset_t *c;
	c = createSet(c);
	for(int i = 0; i < a->nElements; i++)
	{
		for(int j = 0; j < b->nElements; j++)
		{
			if(strcmp(a->element[i], b->element[j]) == 0)
				cnt++;
		}
	}
 
	for(int i = 0; i < a->nElements; i++)
	{
		for(int j = 0; j < b->nElements; j++)
		{
			if(strcmp(a->element[i], b->element[j]) == 0)
			{
				c->element[k] = a->element[i];
				k++;
				continue;
			}
		}
	}
 
	return c;
}
strset_t *unio(strset_t *a, strset_t *b)
{
	int cnt = 0, k = 0;
	char *kyo;
	strset_t *c;
	c = createSet(c);
	kyo = intersection(a, b);
	cnt = a->nElements + b->nElements;
 
	for(int i = 0; i < a->nElements; i++)
	{
		for(int j = 0; j < b->nElements; j++)
		{
			if(strcmp(a->element[i], b->element[j]) == 0)
				cnt++;
		}
	}
 
	for(int i = 0; i < a->nElements; i++)
	{
		c->element[k] = a->element[i];
		k++;
	}
 
	for(int j = 0; j < cnt; j++)
	{
		removeElement(kyo[j], c);
	}
 
	for(int i = 0; i < b->nElements; i++)
	{
		c->element[k] = b->element[i];
		k++;
	}
 
	return c;
}
strset_t *difference(strset_t *a, strset_t *b)
{
	int cnt = 0, k = 0;
	char *kyo;
	strset_t *c;
	c = createSet(c);
	kyo = intersection(a, b);
	cnt = a->nElements + b->nElements;
 
	for(int i = 0; i < a->nElements; i++)
	{
		for(int j = 0; j < b->nElements; j++)
		{
			if(strcmp(a->element[i], b->element[j]) == 0)
				cnt++;
		}
	}
 
	for(int i = 0; i < a->nElements; i++)
	{
		c->element[k] = a->element[i];
		k++;
	}
 
	for(int i = 0; i < b->nElements; i++)
	{
		c->element[k] = b->element[i];
		k++;
	}
 
	for(int j = 0; j < cnt; j++)
	{
		removeElement(kyo[j], c);
	}
 
	return c;
}
 
int main()
{
	strset_t *s1, *s2, *s3;
	char word;
	char str[100];
	int num;
 
	s1 = createSet(s1); 
	s2 = createSet(s2);
	s3 = createSet(s3);
 
	difference(a, b);//c안에 있는 내용을 어떻게 출력하죠
 
 
		}
	}
}
세벌의 이미지

code 태그 안에 소스 코드를 붙여 넣으면 들여쓰기 됩니다.

https://kldp.org/node/158191

익명 사용자의 이미지

출력이 문제가 아니라, 코드가 뭔가 엉망진창인데요.

위에서부터 읽다가 a = realloc(a, a->arraySize);까지 보고 포기했습니다.

혹시 오프라인에서 도움을 청할 사람이 있나요? (학교/학원 선생님이라던지, 대학 강의 조교라던지)
그렇지 않다면 굉장히 친절한 답변자를 찾아야 할 거에요..

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.