1. ## Adding a string with another string to get the output of the letters added?

Hello, i was wondering how i would add the char of a string to the char of another string... so i can print out each of these. It is for a cypher so it would look like this...
HELLO
+ABABA
=I GMNP

so basically the value of the one added on away from 'A' is how much is added.
Thanks

2. You can use the numeric value of the characters, i.e. 'A' = 41 (assuming ASCII). Then just loop through the strings one character at a time and add them together. The only special case is if char1 + char 2 > 'Z'.

3. If string1 = "HELLO" and string2="ABABA" then
Subtract 'A' from every letter in string2; ABABA becomes 12121
Add the result to string1; H+1 == I, E+2 == G, L+1 == M, etc..
Check if string1[current char] > 'Z', then subtract 'Z'-'A'

4. Originally Posted by _Mike
If string1 = "HELLO" and string2="ABABA" then
Subtract 'A' from every letter in string2; ABABA becomes 12121
Add the result to string1; H+1 == I, E+2 == G, L+1 == M, etc..
Check if string1[current char] > 'Z', then subtract 'Z'-'A'
I tried to do this but it did not work... i'm getting weird chars that are unknow symbols?

5. okay so this is what i've got it's not working for me. any help would be appreciated. Thanks

Code:
```#include<stdio.h>
#include<string.h>
#include<ctype.h>

int
main (int argc, char *argv[]){
int i, j, len_key;
char c;

argv[1][3]='\0';

len_key=strlen(argv[1]);

c=getchar();
for(j=0; c!='\n' && c!=EOF; c=getchar()){
if(j>len_key){
j=0;
}
argv[1][j]=argv[1][j]-'a'+1;
printf("%c", c+argv[1][j]);
j++;
}

if(argc==1){
printf("usage: %s [ -d ] key\n", argv[0]);
return 0;

return 0;
}```

6. Originally Posted by Creedy
okay so this is what i've got it's not working for me. any help would be appreciated. Thanks
Code:
`argv[1][3]='\0';`
why are you doing this?

Code:
```if(j>len_key){
j=0;
}```
You should test for == or >= because you don't want to process the null terminator.
Code:
`argv[1][j]=argv[1][j]-'a'+1;`
I don't know if modifying argv's contents are legal or not. You should probably copy it to a temporary string just to be safe.

Code:
```if(argc==1){
printf("usage: %s [ -d ] key\n", argv[0]);
return 0;```
Missing closing bracket. And you might want to check if the arguments are valid before you process them, not after.
Plus the usage example is missleading. If the user runs the app with
./appname -d key
then "-d" is used as the key.

Edit:
Forgot to say,
in your for loop; if the key is shorter than the string inputted in the loop then you are subtracting 'a' from the key more than once, which is why you are getting weird output.

7. I fixed the argv null issue.
Also I fixed the j greater than equal to lenkey.
It still doesn't work and Im not sure what you mean about where you edited.
because j is increasing.

8. Originally Posted by Creedy
It still doesn't work and Im not sure what you mean about where you edited.
because j is increasing.
If you have "hello" as input and "ab" as key then this is what your loop does:

Code:
```set j to 0
subtract 'a' from (key[j]+1). key[0] = 1
print input[0]+key[0]. ('h'+1, prints 'i')

set j to 1
subtract 'a' from (key[j]+1). key[1] = 2
print input[1]+key[1]. ('e'+2, prints 'g')

set j to 0
subtract 'a' from (key[j]+1) // this is where things go wrong, because key[0] has already been modified once before
print input[2]+key[0]. (prints garbage)```