(C언어)구조체 포인터 이용과 추가적인 것에서 질문 있습니다.

prosten의 이미지

#include<stdio.h>
#include<stdlib.h>
 
 struct student{
       int id;
       char name[20];
 }ss;//struct(구조체 이름){}; :구조체의 기본 form.
           //ss는 전역변수 
 
int main (void){
    struct student s; //s는 지역변수 
 
   printf("ID와 이름을 입력해주세요 :");
   scanf("%d %s", &s.id, s.name);
 
    printf("입력받은 ID : %d\n", s.id);
    printf("입력받은 이름 : %s\n", s.name);                
 
    printf("(전역변수) ID와 이름을 입력해주세요 :");
   scanf("%d %s", &ss.id, ss.name);
 
    printf("(전역변수) 입력받은 ID : %d\n", ss.id);
    printf("(전역변수) 입력받은 이름 : %s\n", ss.name);                
 
    system("pause");
    return 0;
}

이라는 C언어 소스에 대해 입출력을 함수로 하고 구조체 포인터로 바꾸는 부분이 영 이해가 되지 않아서 여기에 질문 올립니다. (과제는 아닙니다. 정말요.)
(정확히는 수업 시간에 한 번 한 건데 파일이 날라가서 다시 복구해 보려고 했는데 이해가 안 되서 죄송하지만 이 곳에 질문을 올리게 되었습니다.)

일단은 책을 참고해서 위의 소스를 조건에 맞게, 제 현재 지식 수준으로 바꿔 본 것이

#include<stdio.h>
#include<stdlib.h>
 
 struct student{
       int id;
       char name[20];
 }ss;//struct(구조체 이름){}; :구조체의 기본 form.
           //ss는 전역변수 
 
void input_idname(int s->id, char s->name, struct student *s);
void print_idname(int s->id, char s->name, struct student *s);
int main (void){
    struct student *s; //s는 지역변수 
 
   printf("ID와 이름을 입력해주세요 :");
   scanf("%d %s", &s->id, s->name);
 
    printf("입력받은 ID : %d\n", s->id);
    printf("입력받은 이름 : %s\n", s->name);                             
 
    system("pause");
    return 0;
}
void input_idname(int s->id, char s->name, struct student *s){
      printf("ID와 이름을 입력해주세요 :");
      scanf("%d %s", &s->id, s->name);
void print_idname(int s->id, char s->name, struct student *s){
    printf("입력받은 ID : %d\n", s->id);
    printf("입력받은 이름 : %s\n", s->name);                             
}

인데 컴파일을 하면 함수 프로토타입과 함수에서 s->id, s->name 등에서 syntax error가 발생하였습니다.
대체 어디서 잘못된 것인지...도와주시면 감사하겠습니다.
익명 사용자의 이미지

함수의 매개 변수도 엄연히 변수입니다.
따라서 그 이름은 식별자(identifier) 규칙에 맞아야 합니다.

식별자에는 -, >가 올 수가 없죠. 영문자, 숫자, _만 쓸 수 있으니까요.

의도하셨던 대로 작성하려면 이렇게 하셨어야 하지 않을까 싶습니다.

void input_idname(int *id, char *name) {
printf("ID와 이름을 입력해주세요 :");
scanf("%d %s", id, name);
}
void print_idname(int id, char *name) {
printf("입력받은 ID : %d\n", id);
printf("입력받은 이름 : %s\n", name);
}

댓글 달기

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