Connecting Tech Pros Worldwide Forums | Help | Site Map

Problem in running program but the code compiles succesfully

Newbie
 
Join Date: Oct 2008
Posts: 12
#1: Nov 17 '08
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <cstdlib>
  3.  
  4. using namespace std;
  5.  
  6. char LA;
  7. char* str;
  8. void R(int R_i, int& R_s);
  9. void Digit(int& Digit_val);
  10. void input_error();
  11.  
  12. char token() 
  13. {
  14.      return *str++; 
  15.      }
  16.  
  17. void Num(int& Num_val)
  18. {
  19.   int Digit_value, R_i, R_s;
  20.   Digit(Digit_value);
  21.   R_i = Digit_value;
  22.   R(R_i,R_s);
  23.   Num_val = R_s;
  24. }
  25.  
  26. void R(int R_i, int& R_s)
  27. {
  28.   int Digit_value, R1_i,R1_s;
  29.   if ( LA == '\0' ) 
  30.     R_s = R_i;
  31.   else
  32.   {
  33.     Digit(Digit_value);
  34.     R1_i = 3* R_i + Digit_value;
  35.     R(R1_i,R1_s);
  36.     R_s = R1_s;
  37.   }
  38. }
  39.  
  40. void Digit(int& Digit_val)
  41. {
  42.   LA = token();
  43.   if ( LA == '0' ) Digit_val = 1;
  44.   else if ( LA == '1' ) Digit_val = 0;
  45.   else if ( LA == '\0' ) return;
  46.   else input_error();
  47. }
  48.  
  49.  
  50. void input_error() 
  51. { cout << "unacceptable character" << endl; }
  52.  
  53. int main(int argc, char *argv[])
  54.   str = argv[1];
  55.   int str_value;
  56.   cout << str << endl;  
  57.   Num(str_value);
  58.   cout << "value = " << str_value << endl;
  59. }
  60.  

Ganon11's Avatar
Moderator
 
Join Date: Oct 2006
Location: New York, United States of America
Posts: 3,428
#2: Nov 18 '08

re: Problem in running program but the code compiles succesfully


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?
Newbie
 
Join Date: Oct 2008
Posts: 12
#3: Nov 18 '08

re: Problem in running program but the code compiles succesfully


Quote:

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
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#4: Nov 18 '08

re: Problem in running program but the code compiles succesfully


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?
Newbie
 
Join Date: Oct 2008
Posts: 12
#5: Nov 18 '08

re: Problem in running program but the code compiles succesfully


Quote:

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
Reply


Similar C / C++ bytes