Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Help....

Help....

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sardinka
    wrote on last edited by
    #1

    Why Insert and Delete is not working? char *convert_char_modifier(char *Modifier) { int i; char ch; for (i=0; i < strlen(Modifier);i++) { ch = Modifier[i]; switch (ch) { case 'A': //Delete(i); //Insert(i,"01"); break;:(( :(( sardinka

    M M 2 Replies Last reply
    0
    • S sardinka

      Why Insert and Delete is not working? char *convert_char_modifier(char *Modifier) { int i; char ch; for (i=0; i < strlen(Modifier);i++) { ch = Modifier[i]; switch (ch) { case 'A': //Delete(i); //Insert(i,"01"); break;:(( :(( sardinka

      M Offline
      M Offline
      Michael P Butler
      wrote on last edited by
      #2

      Apart from the fact they are commented out? I think we'll need to see the code for Delete and Insert too. Michael :-)

      S 1 Reply Last reply
      0
      • M Michael P Butler

        Apart from the fact they are commented out? I think we'll need to see the code for Delete and Insert too. Michael :-)

        S Offline
        S Offline
        sardinka
        wrote on last edited by
        #3

        I comment that line out, but even if I uncomment that line it will not work. My code is below: char *convert_char_modifier(char *Modifier) { int i; char ch; for (i=0; i < strlen(Modifier);i++) { ch = Modifier[i]; switch (ch) { case 'A': Insert(i,"01"); break; case 'B': Delete(i); Insert(i,"02"); break; } } return(Modifier); :((

        realJSOPR C 2 Replies Last reply
        0
        • S sardinka

          I comment that line out, but even if I uncomment that line it will not work. My code is below: char *convert_char_modifier(char *Modifier) { int i; char ch; for (i=0; i < strlen(Modifier);i++) { ch = Modifier[i]; switch (ch) { case 'A': Insert(i,"01"); break; case 'B': Delete(i); Insert(i,"02"); break; } } return(Modifier); :((

          realJSOPR Offline
          realJSOPR Offline
          realJSOP
          wrote on last edited by
          #4

          Did you see the code I posted to your earlier question? The reply wasn't actually to you, but to someone else who had replied to your original message. Check it out. By the way, it looks like you're trying to mix CString methods with a simple char array. beyond that, what happens for lower case alpha characters, or characters that aren't letters at all? You have no code to handle those possibilities. Is this a homework assignment? "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

          1 Reply Last reply
          0
          • S sardinka

            I comment that line out, but even if I uncomment that line it will not work. My code is below: char *convert_char_modifier(char *Modifier) { int i; char ch; for (i=0; i < strlen(Modifier);i++) { ch = Modifier[i]; switch (ch) { case 'A': Insert(i,"01"); break; case 'B': Delete(i); Insert(i,"02"); break; } } return(Modifier); :((

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            Gosh, you're doing it the hard way, aren't you ? Like John said, check out the code he posted in reply to my comment ( which was essentially to do what John has shown you, build a second string ). Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001

            1 Reply Last reply
            0
            • S sardinka

              Why Insert and Delete is not working? char *convert_char_modifier(char *Modifier) { int i; char ch; for (i=0; i < strlen(Modifier);i++) { ch = Modifier[i]; switch (ch) { case 'A': //Delete(i); //Insert(i,"01"); break;:(( :(( sardinka

              M Offline
              M Offline
              moliate
              wrote on last edited by
              #6

              This is a solution in plain C. If this is a homework, you should really make sure that you understand the code, and then rewrite it from memory. You will not learn anything otherwise. Also note that more memory than needed may be allocated (what can you do about that?). After seeing some horrible previous posts (think calculator ;P) I had to answer this one to show that a *little* politeless could get you far... /moliate starting to sound 50 year older now, better quit...

              char* convert_char_modifier(char *Modifier)
              {char* tmp = new char[strlen(Modifier)*2];
              char* Result = tmp;

              for (;*Modifier; Modifier++)
              {if (*Modifier >='A' && *Modifier <= 'Z')
              {*tmp++ = char((*Modifier - 'A')/10+'0');
              *tmp++ = char((*Modifier - 'A')%10+'1');
              }
              else
              *tmp++ = *Modifier;
              }

              *tmp = '\0';
              return Result;
              }

              int main(int argc, char* argv[])
              { char* Modifier = "A79867B987C98ZZ";
              printf("%s\n", convert_char_modifier(Modifier) ); // returns 01798670298703982626
              return 0;
              }

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups