Problem separating strings in txt file

Dec 4, 2012 at 10:41pm
Hello, I am currently working on a project that validates passwords. However, we can only use the cstring class. Therefore any function that would be in c++ such as getline is not allowed to be implemented in this project. This is currently the main the dilemma I am facing.

Currently the text file contains a bunch of sample passwords that we read into the project to make testing easier. Below is the txt file.

1
2
3
4
5
6
7
8
9
10
 abcABC1
abcdefABCDEF1234
ASDFGHJKL
asdfghjkl
123456789
snowSNOW
snowSNOW4
2snowSNOW4
snowSNOW34



I have three functions currently. One reads the file in, another checks the file exists, and the last has yet to be coded because I'm currently at a standstill not being able to separate the the passwords. Below is the code I currently have written.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

#include <iomanip>
#include <iostream>
#include <cstdlib>
#include <string.h>
#include <fstream>

using namespace std;

    //Function prototypes
    void fileChecker();
    void readInFile(char);
    void passVal();

int main ()
{
    // Variable Declaration
        char passwords [40];


    // Calling fileChecker function to check if passwd.txt exists
    fileChecker();

    // reading file into a char variable called passwords.
    readInFile(passwords[40]);





}

//Function name: fileChecker
//Purpose : Check if file exists/ and is open
// Parameters :
// Returns: nothing
void fileChecker()
{

   // Read in file
    fstream fin;

    fin.open("passwd.txt");

    // checks if file exists or not.
        if (!fin.is_open())
    {
        cout << "Error, Text file passwd.txt does not exist in current directory." << endl;
        system("PAUSE");
    }

}

//Function name: readInFile
//Purpose : Reads passwd.txt into variable
// Parameters :
// Returns: nothing
void readInFile(char passwords)
{
    fstream fin;
    FILE * pFile;

    fin.open("passwd.txt");
    // while not end of file read / display passwords.
    while(fin.good())
    {
        fin >> passwords;
        fgets (passwords, 20, pFile);
        cout << in << endl;

    }


}
//Function name: passVal
//Purpose : Validating passwords
// Parameters : passwords
// Returns: message stating whether or not a password is valid
void passVal(char passwords)
{
    fstream fin;

    while (fin.good())
    {


    }
}


I'm not sure if the fgets is the correct function to use. All help is greatly appreciated. Thank you all for your time.
Last edited on Dec 4, 2012 at 10:41pm
Topic archived. No new replies allowed.