访问多个源文件之间的库和函数

时间:2017-08-03 05:03:31

标签: c

我正在运行一个程序,该程序利用ncurses library在终端中显示包含正在更新的数据的窗口,并将其插入到我的主源文件的相应窗口中。

multiple windows

我有一个单独的文件,它有自己的头文件,其中包含我想要转换为ncurse函数的printf语句。并在我创建的窗口中显示。

ncurses需要一些设置并使用一些小函数,所以我不确定如何在两个文件中使用它。我尝试将其包含在我的头文件中并链接到我的源文件,但我得到multiple defenitions, first defined here errors.

在我的主文件中设置ncurse窗口:

/* Window defintion constants*/


#define PROTOPORT 36795 /* default protocol port number, booknumber */
#define QLEN 6          /* size of request queue */
#define MAXSIZE 256
#define NUMWINS 7
#define RES_BUF_SIZE 80



WINDOW *w[NUMWINS];
WINDOW *sw[NUMWINS];
WINDOW wh[NUMWINS];

void update_win(int i) {
    touchwin(w[i]);
    wrefresh(sw[i]);
}

/* add string to a window */
void wAddstr(int z, char c[255]);

void GUIshutdown(char * response) {
    wmove(sw[4], 0, 0);
    wclrtoeol(sw[4]);
    wprintw(sw[4], "All finished. Press Enter to terminate the program.");
    update_win(4);
    wgetstr(sw[4], response);
    /* End screen updating */
    endwin();
    echo();
}

//////////
int main(int argc, char *argv[]) {

/***********************************************/
/* setup ncurses for multiple windows          */
/***********************************************/
setlocale(LC_ALL, ""); // this has to do with the character set to use
initscr();
cbreak();
noecho();
nonl();

intrflush(stdscr, FALSE);
keypad(stdscr, TRUE);

/* Clear screen before starting */
clear();
w[0] = newwin(0,0,0,0);


if (LINES != 43 || COLS != 132)  {
    move(0, 0);
    addstr("Piggy3 requires a screen size of 132 columns and 43 rows");
    move(1, 0);
    addstr("Set screen size to 132 by 43 and try again");
    move(2, 0);
    addstr("Press enter to terminate program");
    mvprintw(3,0,"%dx%d\n", COLS, LINES);
    refresh();
    getstr(response); // Pause so we can see the screen
    endwin();
    exit(EXIT_FAILURE);
}

/* create the 7 windows and the seven subwindows*/
for (a = 0; a < NUMWINS; a++) {
    w[a] = newwin(WPOS[a][0], WPOS[a][1], WPOS[a][2], WPOS[a][3]);
    sw[a] = subwin(w[a], WPOS[a][0] - 2, WPOS[a][1] - 2, WPOS[a][2] + 1, WPOS[a][3] + 1);
    scrollok(sw[a], TRUE); // allows window to be automatically scrolled
    wborder(w[a], 0, 0, 0, 0, 0, 0, 0, 0);
    touchwin(w[a]);
    wrefresh(w[a]);
    wrefresh(sw[a]);
}


/***********************************************/
/* Windows                                     */
/***********************************************/

/*
 * Notes:
 *  sw[0] = upper left window,
 *  sw[1] = upper right window,
 *  sw[2] = bottom left window,
 *  sw[3] = bottom right window
 *  sw[4] = bottom command window
 *  sw[5] = bottom inputs window
 *  sw[6] = bottom errors menu.
 */

wmove(sw[0], 0, 0);
wprintw(sw[0], "This is the window where the data flowing from left to right ");
wprintw(sw[0], "will be displayed. Notice now we don't need to worry about when we reach the last ");
wprintw(sw[0], " position in the subwindow, we will just wrap around down to the next line of the subwindow");
wprintw(sw[0], " and can never mess up the border that is in the parent window");

wprintw(sw[inLeft], " Data coming from the left, head piggy\n");


wmove(sw[1], 4, 0);
waddstr(sw[1], "Data leaving right side");
wmove(sw[2], 4, 0);
waddstr(sw[2], "Data leaving the left side");
wmove(sw[3], 4, 0);
waddstr(sw[3], "Data arriving from the right");
wmove(sw[4], 0, 0);
waddstr(sw[4], "Commands: ");
wmove(sw[5], 0, 0);
waddstr(sw[5], "Data Entry: ");
wmove(sw[6], 0, 0);
waddstr(sw[6], "Errors: ");

for (int a = 0; a < NUMWINS; a++){
    update_win(a);
}

wmove(sw[4], 0, 0);
wprintw(sw[4], "Press Enter to see the output in the upper left window scroll");
wgetstr(sw[4], response); // Pause so we can see the screen
wmove(sw[4], 0, 0);
wclrtoeol(sw[4]); // clears current line without clobbering borders
update_win(4);
}

1 个答案:

答案 0 :(得分:1)

你的.h文件中需要标题保护。

   #ifndef HEADER_FILE_NAME_H
   #define HEADER_FILE_NAME_H
    // include,definitions..

    #endif //HEADER_FILE_NAME_H
相关问题