Thread: paralel ascii change of a string..

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Banned
    Join Date
    Aug 2009
    Posts
    43

    paralel ascii change of a string..

    i need to write a function which inputs a string
    and removes all the spaces from the start and removes all the spaces from the end of the string.
    the string consists of words separated by spaces.
    if between two words we have more then one space ,it cuts down the excess spaces
    til its left with one space only between two words.
    and each char is flipped to its parallel ascii value "c" to "x" , "i" to "h" etc..
    for example:
    " C is wonderful "
    turn to
    "X hr ofuivwmld"

    i tried to solve it like this

    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]=c-26+'A';
                           else
                            str[j]=c-26+'a';
                            j++;
                      }
                       str[j]=' ';
                 }
              srt[j-1]='\0';
             return str;
    }
    Last edited by kakaroto; 08-20-2009 at 10:49 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. How properly inherit from template?
    By 6tr6tr in forum C++ Programming
    Replies: 118
    Last Post: 04-25-2008, 04:30 AM
  3. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM