Need help

Hello guys, i'm new here and looking for help. I am stuck with one assigment, and run out of time with it. Need help fast.
Assigment is:
Create a c++ program that reads text from file. Find all words that beggins with the same letter as the first word first letter from the file. All found words sort by alphabet. All results outputs to screen and file.
Who helps will get +1000000 karma points.
Since this is not a homework site, why don't you show us what you have so far? Then you can ask questions about what you don't understand and we can help you.

You learn by doing. If you don't write the code yourself, then (1) you won't learn how to do it and (2) you will be lying to your teacher when you turn in your assignment. There aren't enough karma points available to make me want to cheat you and your teacher.

What are you allowed to use, vector, string,sort..?
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
const char D[]="duom.txt";
const char R[]="rez.txt";

class objektas{
	public: 
	int n=0;
	string h;
	void ska();
	void nuskaityk();
	void rikiuok();
	int M[36];
	int sk =0;};
	
	void objektas::nuskaityk(){
		ifstream d (D);
		ofstream r (R);
		while(!d.eof()){
		getline(d, h);
		cout << h << endl;
		r << h << endl;
		}
		d.close();
		r.close();
		ska();
	};
	
	void objektas::ska(){
		ifstream d (D);
		ofstream r (R, ios::app);
		while(!d.eof()){
			d >> h;
			if(atoi(h.c_str())) if(h.length()>1 && h.length()<3){
				M[n]=atoi(h.c_str());
				n++;	
			}
		}
		rikiuok();
		cout << "\nDvizenkliu skaiciu: " << n << endl;	
		r << "\nDvizenkliu skaiciu: " << n << endl;	
		d.close();
		r.close();
	};
	
	void objektas::rikiuok(){
		ofstream r (R, ios::app);
		for(int i=1;i<n;i++)
		if(M[i-1]>M[i]) swap(M[i-1],M[i]);
		for(int i=0;i<n;i++) {r << M[i]<< " ";cout << M[i]<< " ";}
		r.close();
	}; 
	

int main() {
	objektas l;
	l.nuskaityk();
	return 0;
}

I have this done with numbers and I need to change it to words. With numbers it was easier but now im stuck with words.
I am not sure your numbers version works like you think it does. You read in h in nuskaityk() and then overwrite it immediately in ska(). Also, your sort function (I think that's what rikiuok is) seems to be a bubble sort that is missing its nested loop. The array will not be completely sorted when you are done--only the largest value is guaranteed to be in its proper location.

... but now im stuck with words
That is a pretty broad statement. I don't know what it is you are stuck with.

You can compare the first letter of two strings with if (string1[0] == string2[0]). You can compare alphabetical order of two strings with if (string1 < string2).

By the way, it is safer and more flexible to use std::vector than a raw array. How do you know you only need 36 elements? And what happens if you read in 37? Using a std::vector protects you from this.

In either event, there are std::sort functions you can use to do the sorting for you.
Topic archived. No new replies allowed.