프로그래밍

 3198, 1/160 회원가입  로그인  
   my10045139
   http://lms247.blog.me/
   c언어 구조체 배열 포인터로 함수로 전달하는데...

http://www.hackerschool.org/HS_Boards/zboard.php?AllArticle=true&no=6593 [복사]


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//prototype of function
void printMenu(void);
void addSymbolTable(struct SymbolTable*, int*);
void setSymbolTable(void);
void retrieveSymbolTable(void);

//struct
typedef struct {
    //struct variable
    int no;
    char name[10];
    char type[6];
    char data[7];
    int length;
    int value;
    int base;
    int offset;

} SymbolTable;

int main(int argc, char* argv[])
{
    //variable
    char menu_list[4] = {'Q', 'N', 'E', 'S'};
    char input_menu;
    int symbol_tbl_size = 1;
    int *symbol_size_ptr = &symbol_tbl_size;
    struct SymbolTable *symTbl[symbol_tbl_size];

    //call function
    printMenu();
    while(getc(input_menu != menu_list[0])) {
        if(input_menu == menu_list[1]) addSymbolTable(&symTbl, &symbol_size_ptr);
        else if(input_menu == menu_list[2]) setSymbolTable();
        else if(input_menu == menu_list[3]) retrieveSymbolTable();
        else printf("it's not exist command. please try again after check the command list.");
    }

    return 0;
}

void printMenu(void) {
    //developer information
    printf("A symbol table is used to store and retrieve attributes of"
           "variables declared in a source program during compilation."
           "This program simulates the symbol table usage simply."
           "Created by \n\n");

    //this program explanation
    printf("Current symbol table is empty.\n"
           "Usage: N - add a new variable to the symbol table.\n"
           "\tE - set base address.\n"
           "\tS - retrieve certain variable from the symbol table.\n"
           "\tQ - Exit program.\n\n");
}

void addSymbolTable(struct SymbolTable *tbl, int *tbl_size) {
    tbl[*tbl_size-1] = malloc(sizeof(struct SymbolTable));
    *tbl_size++;

}

에서

void addSymbolTable(struct SymbolTable *tbl, int *tbl_size) {
    tbl[*tbl_size-1] = malloc(sizeof(struct SymbolTable));
    *tbl_size++;

}

의 void addSymbolTable(struct SymbolTable *tbl, int *tbl_size) { 부분에서 에러가가 나고 있습니다..
뭐가 문제인가요?

  Hit : 7837     Date : 2017/12/13 12:04



    
김답변 typedef로 struct를 쓰셨으면 SymbolTable자체가 struct 선언을 갖고 있습니다
struct SymbolTable 이라고 쓰신것들에서 다 struct를 빼시면 됩니다
2017/12/14  
김답변 아 그리고 함수 선언할때 함수선언 아래에서 정의한 type을 쓰고 계시네요
struct정의를 먼저 하신다음에 함수선언을 하셔야 합니다
2017/12/14  
menial 배열 이름 자체가 주소인데 또 주소를 보내나?
지역변수들에 대한 초기값은 안줍니까?
구조체 포인터 배열변수는 초기값을 넣고 시작해야죠
2018/11/21