hello I am new to C++. I understand pointers and references a little and I must be missing something in conf.cpp. Would you help by pointing out my errors for my pointers coding errors related to my problem? Main reason I am asking is because I get a segment fault where 'servername' is.
system header and conf.h's relative include:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
the example varible and an shortcut I picked up the source conf.h:
#define E extern
E string &servername;
termed source of conf.cpp for veiwing purposes:
string &servername;
//parse line
int cur;
int dirint;
int smspace = 1;
void parse(string line) {
string sub;
string pram;
string subval;
int len = line.length();
for (int i = 0; i < len; i++)
{
if (line[i] == '\t') {
} else if (line[i] == '"') {
if (line[i + 1] == ';') {
cout << "|\";|"<< endl;
smspace = 1;
cur = 0;
} else {
cur = 1;
cout << "|\"|";
smspace = 0;
}
}else if(smspace == 1 && line[i] == ' ') {
} else {
if (sub == "servername"){
if (cur == 0)
servername = "test";
cout << &servername;
}
if (cur == 1) {
pram += line[i];
} else {
sub += line[i];
}
}
}
}
void read_conf() {
ifstream in ( CONF_FILE );
if ( in.is_open() )
{
string line;
int ret = 0;
int linenum = 0;
while ( getline ( in, line ) ) {
string::size_type i = line.find_first_not_of ( " \t\n\v" );
linenum++;
if ( i != string::npos && line[i] == '#' )
{
continue;
}
if (ret == 1)
{
if ( i != string::npos && line[i] == '*' )
{
int ptr = i + 1;
if ( i != string::npos && line[ptr] == '/' )
{
ret = 0;
}
continue;
}
}
if ( i != string::npos && line[i] == '/' )
{
int ptr = i + 1;
if ( i != string::npos && line[ptr] == '*' )
{
ret = 1;
continue;
}
};
parse(line);
}
};
};