Simple bigram printing not working

Need help in small part of the assignments

Ok so i am on the last part on my project and everything is running smoothly and boom this hits me.
initially i am suppose to compare bigrams to the passage and count how many times its been use.

BTW bigrams are something aa, ab, ac, ad,.... all the way to zx,zy, zz.

so i tried all the way i thought of but no use. i attached both the codes i experimented with
and also right now im just trying to print it.

i know there is alphabet.at but for some reason that doesnt work.

also
getting segmentation fault

please help!!

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
#include <iostream>
#include <sstream>



using namespace std;


int main()
{

	
	int  bigram_count[26][26];
	string ALPHABET = "abcdefghijklmnopqrstuvwxyz";
	int b[676];
	
	


	for (int i =0 ; i<26 ; i++)
		{
			 for(int j=0; j<26;i++)
			{

			cout<<ALPHABET[j]<<" "<<ALPHABET[i]<<endl ;

			}
		}
	


	
	return 0;

} // end main 


Try 2
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
#include <iostream>
#include <sstream>
#include <queue>
#include <string>


using namespace std;

int main()
{
    
	int  bigram_count[26][26];
	const char ALPHABET[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
	int b[676];
	
		for (int i =0 ; i<26 ; i++){
			for(int j=0; j<26;i++){
				cout<<ALPHABET[j]<<" "<<ALPHABET[i]<<endl ;
			}
		}
return 0;

}
 
 





Thank you for any help,

K
As for crash notice:
1
2
3
4
5
6
7
8
9
for (int i =0 ; i<26 ; i++)
		{
			 for(int j=0; j<26;i++)//should be j++
			{

			cout<<ALPHABET[j]<<" "<<ALPHABET[i]<<endl ;

			}
		}


You are out of bounds with current code!

Also try following if you want aa, ab, ac, ad...za, zb, zc...zz:
1
2
3
4
5
6
7
8
9
for (int i =0 ; i<26 ; i++)
		{
			 for(int j=0; j<26;j++)
			{

			cout<<ALPHABET[i]<<" "<<ALPHABET[j]<<endl ;

			}
		}
Last edited on
Topic archived. No new replies allowed.