List and file

I have a store (txt) file that contains element .
ex:
1
2
3
4
5
6
7
8
     V 4 Potato 2 Tomato 1 carrot 3 onion 1
     F 2 Banana 5 Apple 2
     F 3 Orange 2 Strawberry 5 Kiwi 4
     V 2 Potato 4 Onion 2
     P
     M 3 Strawberry 3 Apple 3 Potato 3
     P
  

V = Vegetable. F = Fruits. M = Mixt. P = Process
Each line correspond to a shopper.
try to get a program that will allow me to process all the lines (Shoppers) of this file.
The problem I have is how to get to the point where the program recognize the end of a shopper's line.
I put all the elements on a list that i named "myList". and contains word by word the element of the file
ex: myList:
Last edited on
just take each of those in a char array

if the second element is '\0' which is the null termination character you know your string had only one character so it can be either a letter or a number so if the first element of the array is between '0' and '9' it is a letter

otherwise you know you got a word

for example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <fstream>

using namespace std;

int main() {

	ifstream in("Text.txt");
	char input[20];
	
	while (!in.eof()) {
		in >> input;
		if (input[0] >= '0' && input[0] <= '9')
			cout << "number ->" << input[0] << endl;
		else
			if (input[1] == '\0')
				cout << "letter ->" << input[0] << endl;
			else
				cout << "word ->" << input << endl;
	}

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