int main(){}안에 void foo(){}를 넣을 수 있나요?

jwmc의 이미지

자료구조 수업 예제 풀던 중 코딩오류로 문의드립니다

#include<stdio.h>
#define SWAP(x,y,t)((t)=(x),(x)=(y),(y)=(t))//The whole code shows reculsive algorithms.
void foo(char list[], int i, int n) {//Therefore, in here, 'foo' is actually permutation
	/*char i_list[] = { 'a','b','c' };//To avoid redefinition, instead of char list[]
	i = 0;//To avoid recursive, instead of foo(list, 0, 2)
	n = 2;*/---->이 부분은 제가 따로 넣었습니다. char list[]={'a','b','c'}, foo(list,0,2)라고 문제에서 주어져 있었습니다. 
	int j, temp;
	if (i == n) {
		for (j = 0;j <= n;j++) printf("%c", list[j]);
		printf(" ");
		}
	else {
		for (j = i; j <= n; j++) {
			SWAP(list[i], list[j], temp);
			foo(list, i + 1, n);
			SWAP(list[i], list[j], temp);//Question: How do you print the result?
			}
		}
	}
}

실행하면 abc acb bac bca cba cab가 나온다는데, 구현에 어려움을 겪고 있습니다.
그대로 VS에 넣으니 오류가 나는데, int main()블록 안에 void foo()블록을 넣을 수 있나요?
온라인 청강이라 교수님께 여쭐 수도 없어 여기 여쭤봅니다.

나빌레라의 이미지

에러 메시지가 뭔가요?

----------------------
얇은 사 하이얀 고깔은 고이 접어서 나빌레라

jwmc의 이미지

LNK2019 _main"int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) 함수에서 확인할 수 없는 외부 기호.
LNK1120 1개의 확인할 수 없는 외부참조입니다.

그런데 int main()을 넣어도 void foo()랑 연결해야 실행 결과가 출력될 것 같아서요.

나빌레라의 이미지

main에서 foo를 호출하세요

----------------------
얇은 사 하이얀 고깔은 고이 접어서 나빌레라

jwmc의 이미지

출력 성공했습니다! 덕분에 함수선언에 대해 찾아보는 계기가 되었습니다. 감사합니다.

댓글 달기

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