d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Another Question In C > This Concerns Strings/char Arrays
Add Reply New Topic New Poll
Member
Posts: 3,210
Joined: Aug 21 2010
Gold: 152.00
Dec 11 2012 03:33pm
I am trying to have this program read

"Hey Everyone Leave Please"

from a text file into the array code

then I want to use a recursive function to go through this string and remove the capitalized letter and read them into another char array or string and then print out the message HELP

Right now it is either going forever after it compiles and runs or if I change a few things it will tell me that on line 36 (The if statement to check for a captial letter in the array) that the char constant is too long for its type.

Anyone have any ideas kn how to fine tune please?

thanks for your time!



Code
#include <stdio.h>

void codeFind(char *, char *, int);

int main() {

char code[30];

char decode[30];

int loc = 0;

FILE *fp;

fp = fopen("Secret Code.txt", "r");
scanf("%s", &code);

codeFind(code, decode, loc);

return 0;


}

void codeFind(char *codeF, char *decodeF, int locF) {

 if (codeF[locF] == '\0') {

 printf("%s\n", decodeF);

}

else {

 
 if ( 'codeF[locF]' >= 'A' && 'codeF[locF]' <= 'Z' ) {

  decodeF[locF] = codeF[locF];

  locF++;

  codeFind(codeF, decodeF, locF);

 }

 else {

  locF++;

  codeFind(codeF, decodeF, locF);

 }
}
}
Member
Posts: 3,210
Joined: Aug 21 2010
Gold: 152.00
Dec 11 2012 03:45pm
I fixed some silly error where I forgot to use the fp and fscanf!

I am now trying to read in HeyEveryLeavePlease

but when i print it out ater it goes through the function the only letter that stays capital is the first H and the rest go down to lower case

I really do not know why this is happening can any help? Here is the new code:

Code
#include <stdio.h>

void codeFind(char *, char *, int);

int main() {

char code[30];

char decode[30];

int loc = 0;

FILE *fp;

fp = fopen("Secret Code.txt", "r");
fscanf(fp, "%s", &code);

printf("%s\n", code);

codeFind(code, decode, loc);

return 0;


}

void codeFind(char *codeF, char *decodeF, int locF) {

 if (codeF[locF] == '.') {

 printf("%s\n", decodeF);

}

else {

 
 if ( codeF[locF] > 'A' && codeF[locF] < 'Z' ) {

  decodeF[locF] = codeF[locF];

  locF++;

  codeFind(codeF, decodeF, locF);

 }

 else {

  printf("%c\n", codeF[locF]);

  locF++;

  codeFind(codeF, decodeF, locF);

 }
}
}


This post was edited by Nom_Nomz on Dec 11 2012 03:49pm
Member
Posts: 3,210
Joined: Aug 21 2010
Gold: 152.00
Dec 11 2012 03:57pm
So I used a bunch of printf statements and the string is always HeyEverybodyLeavePlease except once it goes into that last else statement and it prints out Heyeverybodyleaveplease

Any ideas on why this is happening?

This post was edited by Nom_Nomz on Dec 11 2012 03:58pm
Member
Posts: 3,210
Joined: Aug 21 2010
Gold: 152.00
Dec 11 2012 04:03pm
NVM I got it, I needed a second counter for the decode array.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll