Perhaps you just forgot to add the array The_Valeto the array pKingdoms.
So, something like this will make you understand what you were doing wrong:
, , ;)
#include <iostream>
#include "kingdom.h"
#include <string.h>
using namespace std;
using namespace westeros;
int main(void){
int count = 0;
Kingdom* pKingdoms = new Kingdom[count];
display(pKingdoms, count, "Mordor");
display(pKingdoms, count, "The_Vale");
strcpy(pKingdoms[0].m_name, "The_Vale");
pKingdoms[0].m_population = 1000;
display(pKingdoms, count, "The_Vale");
delete[]pKingdoms;
pKingdoms = nullptr;
return 0;
}
- source.cpp .
#include <iostream>
#include <string>
#include "kingdom.h"
namespace westeros{
void display(Kingdom pKingdom[], int kingdomElement, string KingdomName){
int flag = -1;
cout << " ---------------- " << endl;
cout << " Searching for kingdom " << KingdomName << " in westeros " << endl;
for(int i=0; i<kingdomElement; i++)
if (pKingdom[i].m_name == KingdomName)
flag = i;
if (flag != -1)
{
cout << " --------------------- " << endl;
cout << KingdomName << ", population " << pKingdom[flag].m_population << endl;
cout << " --------------------- " << endl;
}
else{
cout << " --------------------- " << endl;
cout << KingdomName << " is not part of Westeros. " << endl;
cout << " --------------------- " << endl;
}
}
}