문법 좀 도와주세요

javaisland의 이미지

원하는 스트링을 나오게 하고 싶은데 자꾸 쓰래기 값이 찍히네요
좀 부탁 드립니다.

void main(void)
{
char *val = "true"; //true 스트링 입력
test_code(&val); //test_code 함수 호츨 (val 주소를 넘김)
test_code(val); //에러 발생
test_code("true"); //에러 발생
}

void test_code(char *value)
{
printf("=======[TESTCODE] = %s\n", value); //true라고 찍힐줄 알았는데 요상한 도형이 찍힘
printf("=======[TESTCODE] = %s\n", *value); //에러 발생 (warning: passing arg 1 of makes
}

도와주시면 정말 감사 드리겠습니다.

raymundo의 이미지

test_code( val );   // val 값, 즉 문자열의 시작 주소를 넘겨주고
 
void test_code( char * value ) {    // 그 값을 받아서
    printf("%s", value);            // 출력을 하든가
}

test_code( &val );   // val의 주소, 즉 문자열의 시작 주소가 담겨 있는 변수의 주소를 넘겨주고
 
void test_code( char ** value ) {    // 그 주소를 받아서
    printf("%s", *value);            // 주소를 찾아가서 가져온 후 출력을 하든가
}

둘 중 어느 한쪽으로 결정해서 쓰세요.

만일 test_code("hello") 이런 호출을 하고 싶다면 첫번째를 택하셔야겠네요.

좋은 하루 되세요!

javaisland의 이미지

passing arg 1 of makes pointer from integer without a cast
이러한 에러를 뱉으면서 컴파일이 안되네요..ㅠㅠ

jick의 이미지

main을 컴파일할 때 test_code의 프로토타입을 몰라서 생기는 현상입니다.

(1) test_code를 main 앞으로 옮기거나, main 앞에
void test_code(char *value);
를 추가하세요.

(2) 컴파일러 경고는 다 켜고 경고는 곧 에러라는 생각으로 다 잡으세요. gcc라면 -W -Wall을 추천합니다.

raymundo의 이미지

jick 님 말씀처럼 프로토타입을 추가해보시고,

여전히 에러가 난다면 그 시점에 작성하신 코드 전체를 보여주세요.

그리고 코드를 쓰실 때는

(code)
실제 코드
(/code)

이렇게 코드 앞뒤에 code 태그를 붙여주시면 (괄호 대신 부등호를 쓰세요)

실제 코드

이렇게 나와서 읽는 사람들이 좋습니다. :)

좋은 하루 되세요!

댓글 달기

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