함수가있는 my_main.c, my_func.c, 선언이있는 my_func.h라는 파일이 3 개 있습니다. my_main에서C 기본, 문자열 또는 포인터 전달
는 :
이 코드 progem와 my_func.h#include <my_global.h>
#include <mysql.h>
#include <string.h>
char* mysql_user_name;
char* mysql_password;
int sql_user(char* mysql_user_name, char* mysql_password);
int sql_table_length(char* database, char* dtable, char* mysql_user_name, char* mysql_password);
에서 my_func.c
#include "my_func.h"
int sql_user(char* mysql_user_name, char* mysql_password)
{
mysql_user_name = "root";
mysql_password = "1234";
return 0;
}
에서
#include "my_func.h"
char* database = "mydatabase";
char* dtable = "mytable";
sql_user(mysql_user_name, mysql_password);
sql_table_length(database, dtable, mysql_user_name, mysql_password);
는 오류없이 컴파일 내가 좀하고 싶습니다 my_func.c 파일에있는 함수의 사용자 이름과 암호. 그러나 주 모듈에서 선언 된 변수는 접근 가능하고 읽을 수있는 반면 가치는 0x0입니다. 이 구성에서 메인에서 사용자 이름과 비밀번호를 얻으려면 어떻게해야합니까?
mysql_user_name의 정의가 여러 개 있기 때문에 연결해서는 안됩니다 ... –
Kerrek, #ifndef 안에 있지만 단락 코드가 있습니다 ... 어쨌든 도움을 주셔서 감사합니다. –