arrays - Why is nothing being printed? C Programming -


I am creating a program that takes the letter from congress.txt , all the uppercase , Then "change them two letters", (A goes to C) (Jade gets B). But nothing is being printed, my main concern is that if my arrays are being stored and different functions are run properly.

It is in congress.txt :

Congress will not make any law regarding the establishment of religion, or ban on free practice Will apply; Or suppress the speech, or freedom of the press; Or to petition the government for peacefully gathering people, and to redress the complaints.

  # include & lt; Stdio.h & gt; Int Processfile (Int * Store); Int cipher (int * store, int * code); Int outputCode (int * code); Int main (empty) {int store [300], code [300], ii; processFile (store); Cipher (store, code); output code (code); Getchar (); Return 0; } Zero process file (int * store) {int i, a = 0; FILE * f = fopen ("congress.txt", "r"); For (i = 0; a! = EOF;) {fscanf (f, "% c", and one); // Character in a store (a & lt; = 'Z' & A & gt; = 'A') {// store uppercase letters store [i] = a; I ++; } If (a & lt; = 'z' & a & gt; = 'a') {// uppercase letter as a capital letter [i] = a - 32; I ++; }} I ++; Store [i] = '\ 0'; } Zero cipher (int * store, int * code) {int i; (I = 0; Store [i]! = 0; ++ i) {If (store [i] & lt; = 'X' & Store [i]> = 'A') {// test To see if the letter is between A and X code [I] = (four) (store [i] + 2); // changes the letter by two letters} if (store [i] & gt; = 'y' and store [i] & lt; = 'z') {code [i] = (four) (store [ I] - 24); // change for Y and Z A or B respectively)}} zero output code (int * code) {int i, a, b; (A = 0; code [A]! = 0; ++ A) {if (! (A% 50)) // Create a newline printf ("\ n") every 50 characters; } (B = 0; code [a]! = 0 & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; l '; = 5; ++ b) {// 5 is printed in a block of letters, then a spaceprint (" % c ", code [a]); } printf (""); }}    

Many things are wrong in your code - many of which will be your compiler Complaints about

To get started - you do not have return values ​​for int declared jobs, just make them zero , or return something.

Second - You int a; , but proceed to use it like char . Announce how you use it.

Third for the end of the file - test feof (f) not a! = EOF .

Fourth - When you output your code, you have to increase a , otherwise you will get five times the same value:

  VVVVVV JJJJJKKKKKUUUUKKKKKUUUUUUUUU   

etc.

Fifth - Your printing routine does not guarantee that it will stop - if you have any '\ 0' after the other garbage, you will print more garbage (when Until 5 is not a multi-layer). You have to paddle your cipher with zero.

So - the code working:

  contains # lt; Stdio.h & gt; Int Processfile (Int * Store); Int cipher (int * store, int * code); Int outputCode (int * code); Int main (empty) {int store [300], code [300], I; processFile (store); Cipher (store, code); Output code (code); Printf ("\ n ===== \ n \ n"); Return 0; } Int processFile (int * store) {int i; Four A = 0; FILE * f = fopen ("congress.txt", "r"); For (i = 0; feof (f) & amp; i & lt; 299;) {fscanf (f, "% c", and one); // Character in a store (a & lt; = 'Z' & A & gt; = 'A') {// store uppercase letters store [i] = a; I ++; } If (a & lt; = 'z' & a & gt; = 'a') {// uppercase letter as a capital letter [i] = a - 32; I ++; }} Store [i] = '\ 0'; Return 0; } Int cipher (int * store, int * code) {int i; (I = 0; Store [i]! = 0; ++ i) {If (store [i] & lt; = 'X' & Store [i]> = 'A') {// test To see if the letter is between A and X code [I] = (four) (store [i] + 2); // changes the letter by two letters} if (store [i] & gt; = 'y' and store [i] & lt; = 'z') {code [i] = (four) (store [ I] - 24); // (   

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -