arrays, pointers, and i/o files

I am completely new to c++ and dont understand why this program wont let me put in any data. I looked around and I believe I need to use arrays and pointers but I dont understand why or how to use them. My code follows and I would appreciate some help in understanding what I should do. thanks. (what I am trying to do is enter in the info and read it into a file)


#include <fstream>
#include <iostream>
using namespace std;

/**************************************************************
* getName
* Prompt for file name
* Get name
* Return name
* End
****************************************************/
char getName()
{
char name;

cout << "What is the filename of the grades file? ";

cin >> name;

cout << endl;

return name;
}

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

* Prompt number of records
* Get records
* Return records
* End
*********************************************************/
int getNumberOfRecords()
{
int records;

cout << "How many records are in the file? ";

cin >> records;

cout << endl;

return records;
}

/*************************************************************
* getRecordName
* Prompt recordName
* Get recordName
* Return recordName
* End
**************************************************************/
char getRecordName()
{
char recordName;

cout << "Please name the record (no spaces): ";

cin >> recordName;

cout << endl;

return recordName;
}

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

* Prompt points
* Get points
* Return points
* End
***********************************************************/
int getPoints()
{
int points;

cout << "Points possible: ";

cin >> points;

cout<< endl;

return points;
}

/***********************************************************
* getScore
* Prompt score
* Get score
* Return score
* End
************************************************************/
int getScore()
{
int score;

cout << "Enter score: ";

cin >> score;

cout << endl;

return score;
}

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

* Read fileName
* Compare true or false
* For data = 0; data < records; data++
* Send recordName
* Send points
* Send score
* Compare true or false
* End
*************************************************************/
int readFile(char name,
int records,
char recordName,
int points,
int score
)
{
ifstream fin("name");
{
if (fin.fail())
return -1;

for (int data = 0; data < records; data++)
{
fin >> recordName
>> points
>> score;

if (fin.fail())
return -1;
}
}
fin.close();
}

/**********************************************************************
*
***********************************************************************/
int main()
{

char name;
int records;
char recordName;
int points;
int score;

records = getNumberOfRecords();
name = getName();
recordName = getRecordName();
points = getPoints();
score = getScore();

getName();

readFile(name,
records,
recordName,
points,
score
);

return 0;
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
char getName()
{
char name;

cout << "What is the filename of the grades file? ";

cin >> name;

cout << endl;

return name;
}


Not sure what your problem is but you could try using string instead of char. Char is just 1 letter and I don't think you want that.

1
2
3
4
5
6
7
8
9
10
11
12
string getName()
{
string name;

cout << "What is the filename of the grades file? ";

cin >> name;

cout << endl;

return name;
}
Topic archived. No new replies allowed.