Note that there are some explanatory texts on larger screens.

plurals
  1. POLoop crashing program having to do with 2D arrays
    primarykey
    data
    text
    <p>I am creating an encoding program and when I instruct the program to create a 5X5 grid based on the alphabet while skipping over letters that match up to certain pre-defined variables(which are given values by user input during runtime). I have a loop that instructs the loop to keep running until the values that access the array are out of bounds, the loop seems to cause the problem. This code is standardized so there shouldn't be much trouble compiling it in another compiler. Also would it be better to seperate my program into functions? here is the code:</p> <pre><code>#include&lt;iostream&gt; #include&lt;fstream&gt; #include&lt;cstdlib&gt; #include&lt;string&gt; #include&lt;limits&gt; using namespace std; int main(){ while (!cin.fail()) { char type[81]; char filename[20]; char key [5]; char f[2] = "q"; char g[2] = "q"; char h[2] = "q"; char i[2] = "q"; char j[2] = "q"; char k[2] = "q"; char l[2] = "q"; int a = 1; int b = 1; int c = 1; int d = 1; int e = 1; string cipherarraytemplate[5][5]= { {"a","b","c","d","e"}, {"f","g","h","i","j"}, {"k","l","m","n","o"}, {"p","r","s","t","u"}, {"v","w","x","y","z"} }; string cipherarray[5][5]= { {"a","b","c","d","e"}, {"f","g","h","i","j"}, {"k","l","m","n","o"}, {"p","r","s","t","u"}, {"v","w","x","y","z"} }; cout&lt;&lt;"Enter the name of a file you want to create.\n"; cin&gt;&gt;filename; ofstream outFile; outFile.open(filename); outFile&lt;&lt;fixed; outFile.precision(2); outFile.setf(ios_base::showpoint); cin.ignore(std::numeric_limits&lt;int&gt;::max(),'\n'); cout&lt;&lt;"enter your codeword(codeword can have no repeating letters)\n"; cin&gt;&gt;key; while (key[a] != '\0' ){ while(b &lt; 6){ cipherarray[b][c] = key[a]; if ( f == "q" ) { cipherarray[b][c] = f; } if ( f != "q" &amp;&amp; g == "q" ) { cipherarray[b][c] = g; } if ( g != "q" &amp;&amp; h == "q" ) { cipherarray[b][c] = h; } if ( h != "q" &amp;&amp; i == "q" ) { cipherarray[b][c] = i; } if ( i != "q" &amp;&amp; j == "q" ) { cipherarray[b][c] = j; } if ( j != "q" &amp;&amp; k == "q" ) { cipherarray[b][c] = k; } if ( k != "q" &amp;&amp; l == "q" ) { cipherarray[b][c] = l; } a++; b++; } c++; b = 1; } </code></pre> <p><em><strong>while (c &lt; 6 || b &lt; 6){</em></strong></p> <pre><code>if (cipherarraytemplate[d][e] == f || cipherarraytemplate[d][e] == g || cipherarraytemplate[d][e] == h || cipherarraytemplate[d][e] == i || cipherarraytemplate[d][e] == j || cipherarraytemplate[d][e] == k || cipherarraytemplate[d][e] == l){ d++; } else { cipherarray[b][c] = cipherarraytemplate[d][e]; d++; b++; } if (d == 6){ d = 1; e++; } if (b == 6){ c++; b = 1; } </code></pre> <p><em><strong>}</em></strong></p> <pre><code> cout&lt;&lt;"now enter some text."&lt;&lt;endl&lt;&lt;"To end this program press Crtl-Z\n"; while(!cin.fail()){ cin.getline(type,81); outFile&lt;&lt;type&lt;&lt;endl; } outFile.close(); } } </code></pre> <p>I know there is going to be some mid-forties guy out there who is going to stumble on to this post, he's have been programming for 20-some years and he's going to look at my code and say: "what is this guy doing". </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload