Problem in running program but the code compiles succesfully

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hunter123
    New Member
    • Oct 2008
    • 7

    Problem in running program but the code compiles succesfully

    Code:
    #include <iostream>
    #include <cstdlib>
    
    using namespace std;
    
    char LA;
    char* str;
    void R(int R_i, int& R_s);
    void Digit(int& Digit_val);
    void input_error();
    
    char token() 
    {
         return *str++; 
         }
    
    void Num(int& Num_val)
    {
      int Digit_value, R_i, R_s;
      Digit(Digit_value);
      R_i = Digit_value;
      R(R_i,R_s);
      Num_val = R_s;
    }
    
    void R(int R_i, int& R_s)
    {
      int Digit_value, R1_i,R1_s;
      if ( LA == '\0' ) 
        R_s = R_i;
      else
      {
        Digit(Digit_value);
        R1_i = 3* R_i + Digit_value;
        R(R1_i,R1_s);
        R_s = R1_s;
      }
    }
    
    void Digit(int& Digit_val)
    {
      LA = token();
      if ( LA == '0' ) Digit_val = 1;
      else if ( LA == '1' ) Digit_val = 0;
      else if ( LA == '\0' ) return;
      else input_error();
    }
    
    
    void input_error() 
    { cout << "unacceptable character" << endl; }
    
    int main(int argc, char *argv[])
    { 
      str = argv[1];
      int str_value;
      cout << str << endl;  
      Num(str_value);
      cout << "value = " << str_value << endl;
    }
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    Do you want to tell us what this program does? What is should do? Where the error is? Or should we just guess based on the code you've posted?

    Comment

    • hunter123
      New Member
      • Oct 2008
      • 7

      #3
      Originally posted by Ganon11
      Do you want to tell us what this program does? What is should do? Where the error is? Or should we just guess based on the code you've posted?
      it solves the SDT(syntax directed translation)
      we have to solve
      Num -> Digit Num.val := Digit.val
      Num -> Num1 Digit Num.val := 3*Num1.val + D.val
      Digit -> 0 Digit.val := 1
      Digit -> 1 Digit.val := 0
      i have written this program it compiles succesful but when i try it to run my Dev C++ compiler says "Program stop working" i think there might be linking error

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Put some cout statements to decide when the error is being given.
        e.g in your main you are assuming that argv will have at least 2 entries because you are accessing argv[1]. Are you sure that it has at least 2 entries?

        Comment

        • hunter123
          New Member
          • Oct 2008
          • 7

          #5
          Originally posted by r035198x
          Put some cout statements to decide when the error is being given.
          e.g in your main you are assuming that argv will have at least 2 entries because you are accessing argv[1]. Are you sure that it has at least 2 entries?
          i figured ........now its working

          Comment

          Working...