By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,505 Members | 1,761 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,505 IT Pros & Developers. It's quick & easy.

Problem in running program but the code compiles succesfully

P: 7
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.  
Nov 17 '08 #1
Share this Question
Share on Google+
4 Replies


Ganon11
Expert 2.5K+
P: 3,652
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?
Nov 18 '08 #2

P: 7
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
Nov 18 '08 #3

10K+
P: 13,264
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?
Nov 18 '08 #4

P: 7
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
Nov 18 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.