아 멀고도 먼 c의 길 ㅜㅜ.. 도와주세요.

kknd345의 이미지

#include <stdio.h>



struct card{
	char shape;
	char number;
	int pile;
};


int lastcard=52;

void delete_array( struct card *cmpcard[] , int deleteNumber );

void CardInput(char *number, char  *shape)
{
	scanf( "%c%c",number,shape);
}

// currentNumber가 라스트 카드 되는건 넘기지 않는다.
void Check_Samecard( struct card *cmpcard[], int currentNumber ) 
{
	if( cmpcard[currentNumber]->number == cmpcard[currentNumber+1]->number ||
		cmpcard[currentNumber]->shape == cmpcard[currentNumber+1]->shape )
	{
		cmpcard[currentNumber]->pile++;
		cmpcard[currentNumber]->number=cmpcard[currentNumber+1]->number;
		cmpcard[currentNumber]->shape=cmpcard[currentNumber+1]->shape;
		delete_array( cmpcard, currentNumber+1 );
	}
	else
	{
		if( currentNumber + 3 > lastcard )
			return;
		else
		{
			if( cmpcard[currentNumber]->number == cmpcard[currentNumber+3]->number ||
			cmpcard[currentNumber]->shape == cmpcard[currentNumber+3]->shape )
			{
			cmpcard[currentNumber]->pile++;
			cmpcard[currentNumber]->number=cmpcard[currentNumber+3]->number;
			cmpcard[currentNumber]->shape=cmpcard[currentNumber+3]->shape;
			delete_array( cmpcard, currentNumber+3 );
			}
		}
	}
	
	
}


void delete_array( struct card *cmpcard[] , int deleteNumber )
{
	if( deleteNumber == lastcard ) 
	{
		cmpcard[deleteNumber]->pile=0;
	}
	else
	{
		for( ; deleteNumber<=lastcard ; deleteNumber++)
		{
			cmpcard[deleteNumber]->number=cmpcard[deleteNumber+1]->number;
			cmpcard[deleteNumber]->pile=cmpcard[deleteNumber+1]->pile;
			cmpcard[deleteNumber]->shape=cmpcard[deleteNumber+1]->shape;

		}
		lastcard--;
	}

		

}
	

	
void main()
{
	struct card *pcard=new struct card [52];
	

	int post=52;
	int after=53;

	
	for( int i=0; i<52 ; i++)
	{
		[color=blue]CardInput( &pcard[i].number, &pcard[i].shape );[/color]
		pcard[i].pile=1; //초기화
	}

	while( post != after)
	{
		post=lastcard;

		for( i=0; i < lastcard; i++)
		{
			[color=red]Check_Samecard( pcard, i );[/color]
		}
		after=lastcard;
	}
		
	delete[] pcard;
}

컴파일 하니깐 이처럼 에러 나네요.
error C2664: 'Check_Samecard' : cannot convert parameter 1 from 'struct card' to 'struct card *[]'

파라미터 입력은 제대로 한 것 같은데.. 제가 멀 착각 하고 있는것 일까요?

pcard 자체가 포인터 아닌가요?
그리고 pard가 포인트인데 위에서 청색으로 칠한 부분의 pcard[i]-> 이게 아니고 pcard[i]. 이걸로 해야 에러가 안 나는걸까요?

익명 사용자의 이미지

먼저 C 책을 한권 보시길 권해 드립니다.

pointer 의 개념에 주의를 하셔야겠습니다.

원하시는 function 에서 받는 parameter 는 struct card * [] 입니다.

즉 pointer 의 array 가 와야 정상입니다.

지금 main 함수에서 사용하시는 녀석은

pointer type 이지 pointer 의 array type 이 아닙니다.

지금 new 로 pointer 에 assign 해서 사용하고 계신데 ( new 는 참고로

c++ 에서 쓰는 allocation method 입니다. c 에는 원래 존재하지 않습니다. )

이는 pointer 가 array 를 pointing 하고 있을뿐 type 이 pointer 의 array type 이 아닙니다.

즉 원하시는 Same_card 라는 function 은 다시 말하면 pointer 의 pointer type 을

parameter 로 요구하는 것입니다.

그러므로 type 이 다른것을 보내서 error 가 나는 것 입니다.

서지훈의 이미지

void Check_Samecard( struct card *cmpcard[], int currentNumber ) 함수의 argument 선언은 포인터의 배열로 해 놓구. 매개 변수는 struct card *pcard=new struct card [52]; 그냥 포인터로 선언을 해주셨네요.

이 부분부터 조율을 해야할듯 하네요.

일단 함수 선언부분을...
void Check_Samecard( struct card *cmpcard, int currentNumber )
이렇게 해주는게 맞는듯 하네요.

<어떠한 역경에도 굴하지 않는 '하양 지훈'>

#include <com.h> <C2H5OH.h> <woman.h>
do { if (com) hacking(); if (money) drinking(); if (women) loving(); } while (1);

댓글 달기

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