if its 'a' - 'z' range
result ='a'+26-ch;
if its 'A' - 'Z' range
result ='A'+26-ch;
is it ok now?
if its 'a' - 'z' range
result ='a'+26-ch;
if its 'A' - 'Z' range
result ='A'+26-ch;
is it ok now?
Why are you asking here? I already told you an algorithm for it. If you think you have another, you don't need us to verify it for you. You can do that yourself.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
you told me one case which worked
but i couldnt figure out the general case
so i thought of this
Last edited by kakaroto; 08-21-2009 at 02:57 AM.
The other three cases follow the same pattern. Just the characters will be different. Think about what I'm doing there.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
by your formula
result=-(original-'n')+'m'
we need to know the opposite char first in order to get to the result
so its not working
becase 'm' is the result in the first place
so there is a conflicting logic in your solution
am i correct?
If you mean "because 'm' is the result in the first place", no you are not correct, because any letter can be the result. I mean, try it out:
Code:#include <stdio.h> int main(void) { char original; for (original = 'a'; original <= 'z'; original++) { printf("kakaroto's method: %c Mir's method: %c\n", 'a'+26-original, -(original-'n')+'m'); } return 0; }
My solution will only work for 'a' to 'm'. 'n' to 'z' have a slightly different formula.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
but i dont have those cases
i have only two
one if for a to z
one if for A to Z
EDIT: Well what do you know. It does work for 'n' to 'z'.
Last edited by King Mir; 08-21-2009 at 12:26 PM.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
now the reducing of spaces part is ok?Code:char* AtBash(char* text) { int i=0,start,j=0,k; char* word,*str,c; str=text; while (i<strlen(text)) { for(i=0;str[i]!=' ';i++); if (i<strlen(text)) { start=str; for(j=0;((i<strlen(word)-1)&&str!=NULL;i++) word[i-start]=text[i]; strcopy(word,word+1); for (k=0;k<strlen(word);k++) { c=word[k]; if(c>'Z') str[j]= -(cl-'n')+'m' else str[j]= -(cl-'N')+'M''; j++; } str[j]=' '; } srt[j-1]='\0'; return str; }
Last edited by kakaroto; 08-22-2009 at 03:05 AM.
in what loops i need to remove from the sides
and in what
between words
??
any tips on that?