I am attempting to write a program that searches through an array for names
but the loop appears to not even be executing here is the code:
#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {
char* name = new char;
cout << "Enter the name you want to find>";
cin >> name;
char* names[6] = { "keith","brandon","daniel","mom","dad","b" };
int x = 0;
fir (x = 0;x>=sizeof names/names[0];x++) {
if (names[x] == name) {
cout << "We found the name at element " << x <<"!!!\n";
}
else if (x == sizeof names && names[x] != name) {
cout << "We did not not find the name :(\n";
}
else {
cout << "We haven't found the name yet...\n";
}
x++;
}
system("PAUSE");
return 0;
When allocating memory for name, you are creating a single char, the loop is for, not fir and sizeof requires parentheses.
I don't think that names/names[0] makes sense
Trust me, you're never going to use that. There's no point in learning it. You're better off forgetting how to determine the size of a static array using sizeof.