Note that there are some explanatory texts on larger screens.

plurals
  1. POCaesar Cipher Program - Absurd Number in Array Output
    primarykey
    data
    text
    <p>I'm actually writing about the same program as before, but I feel like I've made significant progress since the last time. I have a new question however; I have a function designed to store the frequencies of letters contained within the message inside an array so I can do some comparison checks later. When I ran a test segment through the function by outputting all of my array entries to see what their values are, it seems to be storing some absurd numbers. Here's the function of issue:</p> <pre><code>void calcFreq ( float found[] ) { char infname[15], alpha[27]; char ch; float count = 0; FILE *fin; int i = 0; while (i &lt; 26) { alpha[i] = 'A' + i++; } printf("Please input the name of the file you wish to scan:\n"); scanf("%s", infname); fin = fopen ( infname, "r"); while ( !feof(fin) ) { fscanf(fin, "%c", &amp;ch); if ( isalpha(ch) ) { count += 1; i = 0; if ( islower(ch) ) { ch = toupper(ch); } while ( i &lt; 26 ) { if ( ch == alpha[i] ) { found[i]++; i = 30; } i++; } } } fclose(fin); i = 0; while ( i &lt; 26 ) { found[i] = found[i] / count; printf("%f\n", found[i]); i++; } } </code></pre> <p>At like... found[5], I get this hugely absurd number stored in there. Is there anything you can see that I'm just overlooking? Also, some array values are 0 and I'm pretty certain that every character of the alphabet is being used at least once in the text files I'm using. </p> <p>I feel like a moron - this program should be easy, but I keep overlooking simple mistakes that cost me a lot of time >.> Thank you so much for your help.</p> <p><em>EDIT</em> So... I set the entries to 0 of the frequency array and it seems to turn out okay - in a Linux environment. When I try to use an IDE from a Windows environment, the program does nothing and Windows crashes. What the heck?</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.
 

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