Use pointer to pass an array of structs into function

I'm making a code to validate login information in the console. I'm trying to use a linear search function to validate the user name inputted by the user. I'm trying to pass my array of structures into the search function via pointer, but I think I have a problem with my pointer definitions, please advise?

#include <iostream>
#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;
// Function Prototypes
void readfile();
void getinput();
void processinput();
int linearsearch();

typedef struct UserRecord // struct for login info + typedef for struct
{
string userID;
string password;
int PIN;
};
struct UserRecord table[50]; // array of 50 structs to hold login info
struct UserRecord* ptr;
ptr = &table[50];
// variables/constants
string inputusername; // hold user's username inut
string inputpassword; // hold user's password input
int inputpin; // hold user's PIN input
int users; // hold number of login accounts
int main ()
{

/*results = SearchList (arrayname, maxnumber of elements, int to store value); Not complete, must enter proper parameters */

readfile();
getinput();
int linearsearch(ptr,users, inputusername);
int a;
cin >> a;
return 0;
}

/*
**************************************************
Function definitions

**************************************************
*/

/*
The searchlist function performs a linear search on an
integer array. The array list, which has a maximum of numElems
elements, is searched for the number stored in value. If the
number is found, its array subscript is returned. Otherwise,
-1 is returned indicating the value was not found in the array
*/
int linearsearch(string list[], int numElems, string value) //modify function to search an array of structs
{
int index = 0; // Used as subscript to search array
int position = -1; //To record position of search value
bool found = false; // flag to indicate if value found

while (index < numElems && !found)
{
if (list[index] == value) // if the value is found
{
found = true; // set flag true
position = index; // Record the value's subscript
}
index++; //Go to next element if value not found

}

return position; // return the position, or -1
}

/*search(struct UserRecord *input, struct UserRecord *file, int numberofusers, int &returns){
for(int i .... i<numberofusers i++){
if(whatiputin.UserId == whatthefileis[i].UserId){
if(whatiput.password{
if{
returns = 1;
}
*/

/*
UserRecord func(){
UserRecord temp;
{cin>> User.userID
while(User.userId){ cin.ignore() cin.clear()}

}
cin >> User.pin

return temp;
}*/

void readfile(){

ifstream inFile ("users.txt");
while(!inFile) //loop to notify user of invalid file
{
cout << "Error: File not found. " << endl; // invalid entry occurred

}
inFile >> users; // get the first integer in data file (number of users)

for (int i = 0; i <= users; i++){ // Loop to read login info from data file

inFile >> table[i].userID;
inFile >> table[i].password;
inFile >> table[i].PIN;

}

cout << "Your current number of users is: " << users << endl << endl; // display login information table
cout << "Username" << setw(12) << "Password" << setw(10) << "PIN" << endl;
cout << "________" << setw(12) << "________" << setw(11) << "___" << endl;
//UserRecord whatwastypedin = UserRecord function(
for (int i = 0; i<= users; i++){
cout <<table[i].userID <<setw(12)<<table[i].password <<setw(14)<< table[i].PIN <<endl; // for loop displays login info


}
}

void getinput()
{
cout<<"Please enter username"<<endl;
cin>>inputusername;
cout<<"Please enter password"<<endl;
cin>>inputpassword;
cout<<"Please enter PIN"<<endl;
cin>>inputpin;


}
Line 19: You're attempting to declare a typedef, but don't give the typedef a name.

Line 22: You trying to initialize a variable (ptr). That must be done as part of the definition. You can't have executable code outside of a function.
 
struct UserRecord* ptr = &table[50];


Line 35: Get rid of the int on the front of the line. linearsearch is declared at line 12 not to take any arguments. You're attempting to pass arguments. Why are you passing table[50]? You can't pass a pointer to a struct (ptr) to a function that's expecting an array of strings.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Topic archived. No new replies allowed.