Help with C++ Command Line Program

I need help first finding the exact point size from the input file I'm reading in through command line, so that's what the int extractPointSize() function is used for. This is currently what my code looks like, if you could help me extract the point size, which is the number in the input file, that'd help greatly.

Misc-Crackling-medium-r-normal 12 This is a short line.
misc-Futura Poster-light-r-normal 24 THIS IS A LONGER, MORE EXPENSIVE LINE.
misc-cmr10-medium-r-normal 10 This is cheap.

[code]int main(int argc, char *argv[])
{

// all variables declared
ifstream fin; // reading in the file
ofstream fout; // reading out the file
int cost[256] = { 0 }; //cost array
char openfile[MAX_FILE]; //opening file array
char fontLine[500] = { 0 }; //font line array


//checks to see if user input is matching to format needed
if (argc != 2)
{
cout << "Incorrect input, program4 data.in" << endl;
}

strcpy(openfile, argv[argc - 1]);


//opens file and checks to see if it was opened or not
fin.open(openfile);
if (!fin)
{
cout << "Unable to open the file: data.in" << endl;
fin.close();
return -1;
}

}


int extractPointSize(string input)
{
int Size = 0;
string Temp;

for (size_t i = 0; i < input.length(); ++i)
{
if (isdigit(input[i]))
{
if (isspace(input[i - 1]))
{
Temp = input.substr(i, string::npos);
Size = strtoul(Temp.c_str(), NULL, 0);

return Size;
}
}
{

return 0; //NOT FOUND
}
}
}

void sortByCost();

void readFontData();

int getTonerUsed();

void printUsage();[\code]

Last edited on
Way too much text to read mate. Narrow your problem down to pieces and ask specific questions.

And please use code tags for your code - http://www.cplusplus.com/articles/jEywvCM9/
I need help first finding the exact point size from the input file I'm reading in through command line, so that's what the int extractPointSize() function is used for. This is currently what my code looks like, if you could help me extract the point size, which is the number in the input file, that'd help greatly.

Misc-Crackling-medium-r-normal 12 This is a short line.
misc-Futura Poster-light-r-normal 24 THIS IS A LONGER, MORE EXPENSIVE LINE.
misc-cmr10-medium-r-normal 10 This is cheap.

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
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
#include <cstdlib>
#include <algorithm>
using namespace std;

const int MAX_FILE = 1000;


int main(int argc, char *argv[])
{
	ifstream fin;
	ofstream fout;
	char openfile[MAX_FILE];
	char fontLine[500] = { 0 };


	if (argc != 2)
	{
		cout << "Incorrect input, program4 data.in" << endl;
	}

	strcpy(openfile, argv[argc - 1]);

	fin.open(openfile);
	if (!fin)
	{
		cout << "Unable to open the file: data.in" << endl;
		fin.close();
		return -1;
	}
	
}

int extractPointSize()
{
	ifstream fin;
	{
		unsigned long Size = 0;
		string Temp;

		for (size_t i = 0; i < str.length(); ++i)
		{
			if (isdigit(str[i]))
			{
				if (isspace(str[i - 1]))
				{
					Temp = str.substr(i, string::npos);
					Size = strtoul(Temp.c_str(), NULL, 0);

					return Size;
				}
			}
		}
		  {
			  return 0; //NOT FOUND

		  }
	}
};

void sortByCost();

void readFontData();

int getTonerUsed();

void printUsage();


Topic archived. No new replies allowed.