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. Parser

Parser

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 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.
  • V Offline
    V Offline
    Verolix
    wrote on last edited by
    #1

    I wrote this string parser. It compiles without errors. But when I launch the program, it doesn't seem to quit the loop.... What's wrong?

    #include int Parse(char *String)
    {
    int Temp = 0;
    int Result = 0;
    int Length = int(strlen(String)); // The length of the string.
    bool Negative = false;
    // Main cycle. Loop through all the symbols of the string.
    for (int i = 0; i < Length; i++)
    {
    if (i = 0)
    {
    // If the first symbol of the string is "-". Make it negative.
    if (String[i] == 45)
    {
    Negative = true;
    }
    }
    else
    {
    // Make sure the input symbol is a number. Return 0 if it's not.
    if (String[i] < 48)
    {
    return 0;
    }
    else if (String[i] > 57)
    {
    return 0;
    }
    else
    {
    // For aech number, perform specific operations.
    switch (String[i])
    {
    // If it's 0.
    case 48:
    Temp = 1;
    for (int j = 0; j < (Length - i); j++)
    {
    Temp *= 10;
    }
    Result += Temp;
    Temp = 0;
    break;
    // If it's 1.
    case 49:
    Temp = 1;
    for (int j = 0; j < (Length - i); j++)
    {
    Temp *= 10;
    }
    Result += Temp;
    Temp = 0;
    break;
    // If it's 2.
    case 50:
    Temp = 2;
    for (int j = 0; j < (Length - i); j++)
    {
    Temp *= 10;
    }
    Result += Temp;
    Temp = 0;
    break;
    // If it's 3.
    case 51:
    Temp = 3;
    for (int j = 0; j < (Length - i); j++)
    {
    Temp *= 10;
    }
    Result += Temp;
    Temp = 0;
    break;
    // If it's 4.
    case 52:
    Temp = 4;
    for (int j = 0; j < (Length - i); j++)
    {
    Temp *= 10;
    }
    Result += Temp;
    Temp = 0;
    break;
    // If it's 5.
    case 53:
    Temp = 5;
    for (int j = 0; j < (Length - i); j++)
    {
    Temp *= 10;
    }
    Result += Temp;
    Temp = 0;
    break;
    // If it's 6.
    case 54:
    Temp = 6;
    for (int j = 0; j < (Length - i); j++)
    {
    Temp *= 10;
    }
    Result += Temp;
    Temp = 0;
    break;
    // If it's 7.
    case 55:
    Temp = 7;
    for (int j = 0; j < (Length - i); j++)
    {
    Temp *= 10;
    }
    Result += Temp;
    Temp = 0;
    break;
    // If it's 8.
    case 56:
    Temp = 8;
    for (int j = 0; j < (Length - i); j++)
    {
    Temp *= 10;
    }
    Result += Temp;
    Temp = 0;
    break;
    // If it's 9.
    case 57:
    Temp = 9;
    for (int j = 0;

    Y D A T 4 Replies Last reply
    0
    • V Verolix

      I wrote this string parser. It compiles without errors. But when I launch the program, it doesn't seem to quit the loop.... What's wrong?

      #include int Parse(char *String)
      {
      int Temp = 0;
      int Result = 0;
      int Length = int(strlen(String)); // The length of the string.
      bool Negative = false;
      // Main cycle. Loop through all the symbols of the string.
      for (int i = 0; i < Length; i++)
      {
      if (i = 0)
      {
      // If the first symbol of the string is "-". Make it negative.
      if (String[i] == 45)
      {
      Negative = true;
      }
      }
      else
      {
      // Make sure the input symbol is a number. Return 0 if it's not.
      if (String[i] < 48)
      {
      return 0;
      }
      else if (String[i] > 57)
      {
      return 0;
      }
      else
      {
      // For aech number, perform specific operations.
      switch (String[i])
      {
      // If it's 0.
      case 48:
      Temp = 1;
      for (int j = 0; j < (Length - i); j++)
      {
      Temp *= 10;
      }
      Result += Temp;
      Temp = 0;
      break;
      // If it's 1.
      case 49:
      Temp = 1;
      for (int j = 0; j < (Length - i); j++)
      {
      Temp *= 10;
      }
      Result += Temp;
      Temp = 0;
      break;
      // If it's 2.
      case 50:
      Temp = 2;
      for (int j = 0; j < (Length - i); j++)
      {
      Temp *= 10;
      }
      Result += Temp;
      Temp = 0;
      break;
      // If it's 3.
      case 51:
      Temp = 3;
      for (int j = 0; j < (Length - i); j++)
      {
      Temp *= 10;
      }
      Result += Temp;
      Temp = 0;
      break;
      // If it's 4.
      case 52:
      Temp = 4;
      for (int j = 0; j < (Length - i); j++)
      {
      Temp *= 10;
      }
      Result += Temp;
      Temp = 0;
      break;
      // If it's 5.
      case 53:
      Temp = 5;
      for (int j = 0; j < (Length - i); j++)
      {
      Temp *= 10;
      }
      Result += Temp;
      Temp = 0;
      break;
      // If it's 6.
      case 54:
      Temp = 6;
      for (int j = 0; j < (Length - i); j++)
      {
      Temp *= 10;
      }
      Result += Temp;
      Temp = 0;
      break;
      // If it's 7.
      case 55:
      Temp = 7;
      for (int j = 0; j < (Length - i); j++)
      {
      Temp *= 10;
      }
      Result += Temp;
      Temp = 0;
      break;
      // If it's 8.
      case 56:
      Temp = 8;
      for (int j = 0; j < (Length - i); j++)
      {
      Temp *= 10;
      }
      Result += Temp;
      Temp = 0;
      break;
      // If it's 9.
      case 57:
      Temp = 9;
      for (int j = 0;

      Y Offline
      Y Offline
      Yulianto
      wrote on last edited by
      #2

      just debug it, trace the variable value.


      Work hard and a bit of luck is the key to success.

      You don`t need to be genius, to be rich.

      1 Reply Last reply
      0
      • V Verolix

        I wrote this string parser. It compiles without errors. But when I launch the program, it doesn't seem to quit the loop.... What's wrong?

        #include int Parse(char *String)
        {
        int Temp = 0;
        int Result = 0;
        int Length = int(strlen(String)); // The length of the string.
        bool Negative = false;
        // Main cycle. Loop through all the symbols of the string.
        for (int i = 0; i < Length; i++)
        {
        if (i = 0)
        {
        // If the first symbol of the string is "-". Make it negative.
        if (String[i] == 45)
        {
        Negative = true;
        }
        }
        else
        {
        // Make sure the input symbol is a number. Return 0 if it's not.
        if (String[i] < 48)
        {
        return 0;
        }
        else if (String[i] > 57)
        {
        return 0;
        }
        else
        {
        // For aech number, perform specific operations.
        switch (String[i])
        {
        // If it's 0.
        case 48:
        Temp = 1;
        for (int j = 0; j < (Length - i); j++)
        {
        Temp *= 10;
        }
        Result += Temp;
        Temp = 0;
        break;
        // If it's 1.
        case 49:
        Temp = 1;
        for (int j = 0; j < (Length - i); j++)
        {
        Temp *= 10;
        }
        Result += Temp;
        Temp = 0;
        break;
        // If it's 2.
        case 50:
        Temp = 2;
        for (int j = 0; j < (Length - i); j++)
        {
        Temp *= 10;
        }
        Result += Temp;
        Temp = 0;
        break;
        // If it's 3.
        case 51:
        Temp = 3;
        for (int j = 0; j < (Length - i); j++)
        {
        Temp *= 10;
        }
        Result += Temp;
        Temp = 0;
        break;
        // If it's 4.
        case 52:
        Temp = 4;
        for (int j = 0; j < (Length - i); j++)
        {
        Temp *= 10;
        }
        Result += Temp;
        Temp = 0;
        break;
        // If it's 5.
        case 53:
        Temp = 5;
        for (int j = 0; j < (Length - i); j++)
        {
        Temp *= 10;
        }
        Result += Temp;
        Temp = 0;
        break;
        // If it's 6.
        case 54:
        Temp = 6;
        for (int j = 0; j < (Length - i); j++)
        {
        Temp *= 10;
        }
        Result += Temp;
        Temp = 0;
        break;
        // If it's 7.
        case 55:
        Temp = 7;
        for (int j = 0; j < (Length - i); j++)
        {
        Temp *= 10;
        }
        Result += Temp;
        Temp = 0;
        break;
        // If it's 8.
        case 56:
        Temp = 8;
        for (int j = 0; j < (Length - i); j++)
        {
        Temp *= 10;
        }
        Result += Temp;
        Temp = 0;
        break;
        // If it's 9.
        case 57:
        Temp = 9;
        for (int j = 0;

        D Offline
        D Offline
        Dreamz
        wrote on last edited by
        #3

        [DFS] Zero wrote: if (i = 0) { if(i == 0) :)

        1 Reply Last reply
        0
        • V Verolix

          I wrote this string parser. It compiles without errors. But when I launch the program, it doesn't seem to quit the loop.... What's wrong?

          #include int Parse(char *String)
          {
          int Temp = 0;
          int Result = 0;
          int Length = int(strlen(String)); // The length of the string.
          bool Negative = false;
          // Main cycle. Loop through all the symbols of the string.
          for (int i = 0; i < Length; i++)
          {
          if (i = 0)
          {
          // If the first symbol of the string is "-". Make it negative.
          if (String[i] == 45)
          {
          Negative = true;
          }
          }
          else
          {
          // Make sure the input symbol is a number. Return 0 if it's not.
          if (String[i] < 48)
          {
          return 0;
          }
          else if (String[i] > 57)
          {
          return 0;
          }
          else
          {
          // For aech number, perform specific operations.
          switch (String[i])
          {
          // If it's 0.
          case 48:
          Temp = 1;
          for (int j = 0; j < (Length - i); j++)
          {
          Temp *= 10;
          }
          Result += Temp;
          Temp = 0;
          break;
          // If it's 1.
          case 49:
          Temp = 1;
          for (int j = 0; j < (Length - i); j++)
          {
          Temp *= 10;
          }
          Result += Temp;
          Temp = 0;
          break;
          // If it's 2.
          case 50:
          Temp = 2;
          for (int j = 0; j < (Length - i); j++)
          {
          Temp *= 10;
          }
          Result += Temp;
          Temp = 0;
          break;
          // If it's 3.
          case 51:
          Temp = 3;
          for (int j = 0; j < (Length - i); j++)
          {
          Temp *= 10;
          }
          Result += Temp;
          Temp = 0;
          break;
          // If it's 4.
          case 52:
          Temp = 4;
          for (int j = 0; j < (Length - i); j++)
          {
          Temp *= 10;
          }
          Result += Temp;
          Temp = 0;
          break;
          // If it's 5.
          case 53:
          Temp = 5;
          for (int j = 0; j < (Length - i); j++)
          {
          Temp *= 10;
          }
          Result += Temp;
          Temp = 0;
          break;
          // If it's 6.
          case 54:
          Temp = 6;
          for (int j = 0; j < (Length - i); j++)
          {
          Temp *= 10;
          }
          Result += Temp;
          Temp = 0;
          break;
          // If it's 7.
          case 55:
          Temp = 7;
          for (int j = 0; j < (Length - i); j++)
          {
          Temp *= 10;
          }
          Result += Temp;
          Temp = 0;
          break;
          // If it's 8.
          case 56:
          Temp = 8;
          for (int j = 0; j < (Length - i); j++)
          {
          Temp *= 10;
          }
          Result += Temp;
          Temp = 0;
          break;
          // If it's 9.
          case 57:
          Temp = 9;
          for (int j = 0;

          A Offline
          A Offline
          Antony M Kancidrowski
          wrote on last edited by
          #4

          You may want to start and write defensively. Instead of if (i == 0) Write if (0 == i) In this case you can not change the value of i by accident. It is so easy to leave out an equal sign. :) Ant. I'm hard, yet soft.
          I'm coloured, yet clear.
          I'm fruity and sweet.
          I'm jelly, what am I? Muse on it further, I shall return!
          - David Walliams (Little Britain)

          1 Reply Last reply
          0
          • V Verolix

            I wrote this string parser. It compiles without errors. But when I launch the program, it doesn't seem to quit the loop.... What's wrong?

            #include int Parse(char *String)
            {
            int Temp = 0;
            int Result = 0;
            int Length = int(strlen(String)); // The length of the string.
            bool Negative = false;
            // Main cycle. Loop through all the symbols of the string.
            for (int i = 0; i < Length; i++)
            {
            if (i = 0)
            {
            // If the first symbol of the string is "-". Make it negative.
            if (String[i] == 45)
            {
            Negative = true;
            }
            }
            else
            {
            // Make sure the input symbol is a number. Return 0 if it's not.
            if (String[i] < 48)
            {
            return 0;
            }
            else if (String[i] > 57)
            {
            return 0;
            }
            else
            {
            // For aech number, perform specific operations.
            switch (String[i])
            {
            // If it's 0.
            case 48:
            Temp = 1;
            for (int j = 0; j < (Length - i); j++)
            {
            Temp *= 10;
            }
            Result += Temp;
            Temp = 0;
            break;
            // If it's 1.
            case 49:
            Temp = 1;
            for (int j = 0; j < (Length - i); j++)
            {
            Temp *= 10;
            }
            Result += Temp;
            Temp = 0;
            break;
            // If it's 2.
            case 50:
            Temp = 2;
            for (int j = 0; j < (Length - i); j++)
            {
            Temp *= 10;
            }
            Result += Temp;
            Temp = 0;
            break;
            // If it's 3.
            case 51:
            Temp = 3;
            for (int j = 0; j < (Length - i); j++)
            {
            Temp *= 10;
            }
            Result += Temp;
            Temp = 0;
            break;
            // If it's 4.
            case 52:
            Temp = 4;
            for (int j = 0; j < (Length - i); j++)
            {
            Temp *= 10;
            }
            Result += Temp;
            Temp = 0;
            break;
            // If it's 5.
            case 53:
            Temp = 5;
            for (int j = 0; j < (Length - i); j++)
            {
            Temp *= 10;
            }
            Result += Temp;
            Temp = 0;
            break;
            // If it's 6.
            case 54:
            Temp = 6;
            for (int j = 0; j < (Length - i); j++)
            {
            Temp *= 10;
            }
            Result += Temp;
            Temp = 0;
            break;
            // If it's 7.
            case 55:
            Temp = 7;
            for (int j = 0; j < (Length - i); j++)
            {
            Temp *= 10;
            }
            Result += Temp;
            Temp = 0;
            break;
            // If it's 8.
            case 56:
            Temp = 8;
            for (int j = 0; j < (Length - i); j++)
            {
            Temp *= 10;
            }
            Result += Temp;
            Temp = 0;
            break;
            // If it's 9.
            case 57:
            Temp = 9;
            for (int j = 0;

            T Offline
            T Offline
            toxcct
            wrote on last edited by
            #5

            why not edit you message and put your code into a <pre></pre> block for helping us to see the indentation ?!:suss:


            TOXCCT >>> GEII power
            [toxcct][VisualCalc]

            V 1 Reply Last reply
            0
            • T toxcct

              why not edit you message and put your code into a <pre></pre> block for helping us to see the indentation ?!:suss:


              TOXCCT >>> GEII power
              [toxcct][VisualCalc]

              V Offline
              V Offline
              Verolix
              wrote on last edited by
              #6

              Thanks everyone. :) And I modified the message a little...

              T 1 Reply Last reply
              0
              • V Verolix

                Thanks everyone. :) And I modified the message a little...

                T Offline
                T Offline
                toxcct
                wrote on last edited by
                #7

                oh, that's better now ;) but the #include still don't appear. be carful to type & l t ; to see a < and a & g t ; for a >. ok, now, you parser seem to be parser a little than one i wrote before. I cannot say to you what is wrong in your code, but I can give you an advice. see the source of my VisualCalc to perform your code... If you need any question about your source, ask it to me here ; if it is about my code, post your request at the bottom of the VisualCalc article. See you,


                TOXCCT >>> GEII power
                [toxcct][VisualCalc]

                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