EDIT: IGNORE THIS POST - I'M AN IDIOT. DIDN'T CREATE THE ARRAY OF STRUCTS BIG ENOUGH.
Hi people!
I'm having some problems inserting a string value into a struct.
I've got two ways I've done it, and only one of these ways works...
Basically, I'm parsing some text output from iwconfig and ifconfig. Originally, I just parsed the text into a string then printed the value to stdout. This worked absolutely fine, but I'm trying to neaten the whole thing up and modularise it by inserting the info into an array of structs instead of just printing it to the terminal. The problem I've got is that for values without [SPACE] chars in it appears to work without a hitch, but there's an ESSID I'm trying to enter ("print server 20CE46"), which gives me a segfault when I try to insert it.
Here's my original code:
Code:
int nPos_essid = tmpIWLIST.find("ESSID");
string tmpIWLIST_essid = tmpIWLIST.erase(0, nPos_essid).substr(7, tmpIWLIST.substr(nPos_essid+7).find("\""));
cout << i << ":ESSID:" << tmpIWLIST_essid << endl;
I'm trying to replace it with this:
Code:
struct stNetwork
{
string address;
string vendor;
string essid;
string mode;
string quality;
string signal;
string encryption;
string enctype;
};
stNetwork networkList[nNumNetworks];
// i-1 used because i starts at 1, and the array starts at 0
networkList[i-1].essid = tmpIWLIST.erase(0, nPos_essid).substr(7, tmpIWLIST.substr(nPos_essid+7).find("\""));
Well, that's a simplified version with all of the middle bits removed, but I'm sure you get the idea. What I'm confused about is why I can insert the value into a normal string fine, but when I try to insert it into a string which is part of a struct I get a segfault.
Anyway, any ideas would be much appreciated.
Thanks!!!
X-T