Hi guys,
When I run this code, I got segmentation fault and i can't figure out where the mistake is? I'd really appreciate any help. thanks
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main ()
{
ifstream file, dest;
file.open ("arp.txt");
if (!file)
{
cout << "Unable to open file"; // if file doesn't exist
exit(1);
}
int size = 16;
string v, ip[15], mac[15], IPs, IPd;
for (int k = 0; k < size; k++) // reading the first file
{
file >> v >> v >> v >> ip[k] >> mac[k]; // v reads all the things before the IP
}
file.close ();
dest.open ("dest.txt");
if (!file)
{
cout << "Unable to open file"; // if file doesn't exist
exit(1);
}
int s, d, z;
dest >> v >> v >> v >> s; // here s will read an integer number from 0 - 15
IPs = ip[s];
dest >> v >> v >> IPd; // IPd will have an IP address that similar to one of the ip[k]
for (int m = 0; m < size; m++)
{
if (IPd == ip[m])
{
d = m;
}
}