Encyption

This is a discussion on Encyption within the C Programming forums, part of the General Programming Boards category; the code is suppose to add an ASCII value 1 to every cell of the array of the input from ...

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    7

    Encyption

    the code is suppose to add an ASCII value 1 to every cell of the array of the input from the user.
    for example:
    user input: ABC
    the result should be: DEF
    but the problem with my code is that it display the result which is JKL.
    Can anyone teach me on this?

    here is my code:
    void StringEncrypt( char input[]){
    for( i=0; i < strlen( input ); i++)
    input[i]=input[i]+3;
    printf("Result : %s",input);
    }

  2. #2
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    This works for me so give it a try:
    Code:
    #include <stdio.h>
    #include <string.h>
    
    int main(void){
    	char Input[4] = "ABC";
    	StringEncrypt(Input);
    	return 0;
    }
    
    void StringEncrypt( char input[]){
    	for(int i=0; i < strlen( input ); i++)
    		input[i]=input[i]+3;
    	printf("Result : %s",input);
    }
    - Sean
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21