Thread: Arthimatic with strings

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    7

    Arthimatic with strings

    So i have been developing some code, what i want to do is
    i have 2 arrays

    Code:
    int souce[255]
    int destination[255]
    what i want to do is go character by character and do some arthimathic on these chars and store that in the destination.

    any idea on how this can be done, i'm reluctant to post my code as this is meant to be a huge project, i'm just stuck on this part.
    its an encryption method
    thanks in advance
    Last edited by Salem; 09-22-2011 at 11:48 PM. Reason: Remove text from code tags

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Is it that difficult to iterate an array?
    Devoted my life to programming...

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    As GReaper says this is butt simple stuff... loops and a bit of math...

    arrayB[i] = arrayA[i] + 13;

    See, not hard at all.

  4. #4
    Registered User
    Join Date
    Sep 2011
    Posts
    7
    Perphaps i wasn't clear on what i was trying to do, sorry about that
    Code:
    char Source[255]
    char dest[255]
    for(i=1;i<255;i++){
    dest[i]=(source[i]*5)%8;
    i want to be able to something like that please help
    Thanks in advance
    Last edited by Salem; 09-22-2011 at 11:49 PM. Reason: fix code tags

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Aside from a few missing semi-colons and mismatched brackets... you just did...

    Really it's just not that difficult...

    Although I should warn you that if that's an encryption algortythm your Source text would be unrecoverable since every character would be reduced to a value between 0 and 7 by the %8 operation... and there'd be no way to backtrack that to the original text.

    Code:
    #include <stdio.h>
    
    int main(void)
     {
       char Source[255];
       char dest[255] = {0};
       int length
    
       strcpy(Source, "Hello World");
       length = strlen(Source);
    
       for(i=0; i < length ;i++)
         {
           dest[i] = Source[i] + 13;  // simple ROT13 encryption
         }
    
       printf("%s \n", dest);
    
       return 0;
    }
    What you need to do is climb into a good book or tutorial on C ... read page by page, compile the examples, do the exercises... actually learn C ... you'll be glad you did.
    Last edited by CommonTater; 09-22-2011 at 11:49 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Swapping strings in an array of strings
    By dannyzimbabwe in forum C Programming
    Replies: 3
    Last Post: 03-03-2009, 12:28 PM
  2. malloc() strings VS array strings
    By Kleid-0 in forum C Programming
    Replies: 5
    Last Post: 01-10-2005, 10:26 PM
  3. Table mapping Strings to Strings
    By johnmcg in forum C Programming
    Replies: 4
    Last Post: 09-05-2003, 11:04 AM
  4. converting c style strings to c++ strings
    By fbplayr78 in forum C++ Programming
    Replies: 6
    Last Post: 04-14-2003, 03:13 AM
  5. finding strings in strings
    By watshamacalit in forum C Programming
    Replies: 14
    Last Post: 01-11-2003, 01:08 AM