Manipulating an file

My program right now has me read in a file for my program, which contains this text:

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.

I need to figure out how to manipulate these strings to pull out the point size ( the point size being the number in the input string ) and that's all I need the function :: int extractPointSize() :: to do. If anyone could tell me how I could do so, please let me know.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
unsigned long extractPointSize(std::string input)
{
        unsigned long Size = 0;
        std::string Temp;

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

                    return Size;
                }
              }
          {

          return 0; //NOT FOUND

}


Include the cctype and cstdlib header files.

EDIT: Missed a bracket :p
Last edited on
Hey Computer Geek, I currently have the program like such.

The thing is I need to store the contents of this file into an array, and then manipulate these said arrays to extract the point size, so I'm confused on how it would work in my code.

#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;




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
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.