我对以下代码有疑问:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gnokii.h>
#define CONFIG_FILE "config"
struct gn_statemachine *state;
void terminate(void) {
gn_lib_phone_close(state);
gn_lib_phoneprofile_free(&state);
gn_lib_library_free();
}
int main() {
gn_data data;
gn_error error;
gn_sms_folder_list folderlist;
atexit(terminate);
if((error = gn_lib_phoneprofile_load(CONFIG_FILE,&state))
!= GN_ERR_NONE)
{
fprintf(stderr,"%s\n",gn_error_print(error));
exit(1);
}
memset(&folderlist,0,sizeof(gn_sms_folder_list));
gn_data_clear(&data);
data.sms_folder_list = &folderlist;
error = gn_sm_functions(GN_OP_GetSMSFolders, &data, state);
printf("ada %d sms dun\n",folderlist.number);
return 0;
}
我正在用 编译它gcc -o main main.c -lgnokii
,但是当它执行时,它会在查找配置文件时产生错误:
# ./gnokiitest
No phone_config section in the config file.
Either global or given phone section cannot be found.
Segmentation fault
因为我将配置文件包含在主输出的一个文件夹中:
$ cat config
[global]
connection = bluetooth
port = 24:22:AB:AB:C1:F8
model = AT
rfcomm_channel = 2
那怎么了?