473,890 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

circular link list in c++

69 New Member
I'm trying to built and array of circular link list but when I read the input file Ijust get a long link list instead of different list and after trying to use Linked_list_Sta ck *obj[arraysize]; I'm getting this errors
newcir.cpp:107: request for member `push' in `obj[i]', which is of
non-aggregate type `Linked_list_St ack*'
newcir.cpp:110: request for member `print_list' in `obj[i]', which is of
non-aggregate type `Linked_list_St ack*'
Oct 20 '06
103 16048
saraSS
69 New Member
still not geting anything the cursor just stay there this is what I'm doing in main
int main( )
{
int m;

Initialize ( ) ;
//cout<<"ok";
cin.getline (postfix,80) ;
cout<<"ok";
SetExpression (postfix) ;
puts(postfix);
strcpy(eval,pos tfix);
m=Evaluate( );
printf("answer: %d", m );
return 0;
}
Oct 22 '06 #41
arne
315 Recognized Expert Contributor
still not geting anything the cursor just stay there this is what I'm doing in main
int main( )
{
int m;

Initialize ( ) ;
//cout<<"ok";
cin.getline (postfix,80) ;
cout<<"ok";
SetExpression (postfix) ;
puts(postfix);
strcpy(eval,pos tfix);
m=Evaluate( );
printf("answer: %d", m );
return 0;
}
But that you see nothing is no related to getline: comment out all other function call (except for the getline, puts and printf functions) and you will see that you read in the data. I guess you have an infinite loop somewhere else :)

You may also add an "endl" io manipulator like
Expand|Select|Wrap|Line Numbers
  1. cout << "ok" << endl;
  2.  
to see where the problem is. Without "endl" the ouput buffer is not flushed. and you cannot see where the program currently is.
Oct 22 '06 #42
saraSS
69 New Member
done that and i print out the ok before that line but not the one after so i think is the get line the mess up
Oct 22 '06 #43
arne
315 Recognized Expert Contributor
done that and i print out the ok before that line but not the one after so i think is the get line the mess up
Try this code (it's _your_ code reduced to the essential parts with only the postfix declaration added):

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace::std;
  3.  
  4. int main( )
  5. {
  6.     int m;
  7.     char postfix[80];     // added this line 
  8.  
  9. //    Initialize ( ) ;
  10.     cout<<"ok" << endl;
  11.     cin.getline (postfix,80) ;
  12.     cout<<"ok" << endl;
  13. //    SetExpression (postfix) ;
  14.     puts(postfix);
  15. //    strcpy(eval,postfix);
  16. //    m=Evaluate( );
  17.     printf("answer: %d", m );
  18.     return 0;
  19. }
  20.  
This runs fine on my machine: It prints "ok" 2 times, the input string and the value of m. No endless loop here.
Oct 22 '06 #44
saraSS
69 New Member
I had char postfix[80]; as a gloval variable but even like the way you told me
still cant get my line ?

Expand|Select|Wrap|Line Numbers
  1.  #include <iostream> 
  2. using namespace std;
  3. #define MAX 80
  4.  
  5. char stack[MAX] ;
  6. char eval[MAX] ;
  7. char *s, *t ; /*pointers to input and output strings*/
  8. int top; /*Stack top*/
  9.  
  10. /*Function Prototypes*/
  11. void Initialize (void);
  12. void SetExpression (char *);
  13. char Pop (void );
  14. void Push (char);
  15. int Evaluate(void);
  16.  
  17. int main( )
  18. {
  19. int m;
  20. char postfix[80]; 
  21.  
  22. Initialize ( ) ;
  23. cout<<"ok";
  24. cin.getline (postfix,80) ;
  25. cout<<"ok";
  26. SetExpression (postfix) ;
  27. puts(postfix);
  28. strcpy(eval,postfix);
  29. m=Evaluate( );
  30. printf("answer: %d", m );
  31. return 0;
  32. }
  33.  
  34. void Initialize (void)
  35. {
  36. top = -1 ;/*Make stack empty*/
  37. }
  38.  
  39. void SetExpression ( char *str )
  40. {
  41. s = str ;
  42. }
  43.  
  44. /* adds operator to the stack */
  45. void Push ( char c )
  46. {
  47. if ( top == MAX - 1 )
  48. printf ( "\nStack is full.\n" ) ;
  49. else
  50. {
  51. top++ ;
  52. stack[top] = c ;
  53. }
  54. }
  55.  
  56. /* pops an operator from the stack */
  57. char Pop ( void )
  58. {
  59. if ( top == -1 ) /* Stack is empty*/
  60. return -1 ;
  61. else
  62. {
  63. char item = stack[top] ;
  64. top-- ;
  65. return item ;
  66. }
  67. }
  68.  
  69. int Evaluate(void)
  70. {
  71. int i,l,a,b,q,z;
  72. l=strlen(eval);
  73. for(i=0;i<l;i++)
  74. {
  75. if ( isdigit ( eval[i] ) )
  76. {
  77. Push(eval[i]);
  78. }
  79. else if ( eval[i] == 'U' || eval[i] == 'I' || eval[i] == '-' || eval[i] == '\' || eval[i] == '=' 
  80. || eval[i] == '<' || eval[i] == '&' || eval[i] == '|' || eval[i] == '&' )
  81. {
  82. a = Pop ( );
  83. b = Pop ( );
  84.  
  85. switch( eval[i] )
  86. {
  87. case 'U' : break;
  88. case 'I' : break;
  89. case '-' : break;
  90. case '\' : break;
  91. case '<' : break;
  92. case '&' : break;
  93. case '|' : break;
  94. case '!' : break;
  95. }
  96. Push ( q );
  97. }
  98. }
  99. z = Pop ( );
  100. return z;
  101. }
  102.  
what I'm doing wrong?
Oct 22 '06 #45
arne
315 Recognized Expert Contributor
See, I just commented out all insignificant function calls. This _definitively_ works and reads in a line from stdin. Please copy and try this code (without all the other functions you have written) in a new program, so that we have a basis on which we can proceed. BTW, the code you posted does not compile. May it be that you change your code, compile, ignore the errors and execute an old executable?

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3. #define MAX 80
  4.  
  5. char stack[MAX] ;
  6. char eval[MAX] ;
  7. char *s, *t ; /*pointers to input and output strings*/
  8. int top; /*Stack top*/
  9.  
  10. /*Function Prototypes*/
  11. void Initialize (void);
  12. void SetExpression (char *);
  13. char Pop (void );
  14. void Push (char);
  15. int Evaluate(void);
  16.  
  17. int main( )
  18. {
  19.     int m;
  20.     char postfix[80];
  21.  
  22. //    Initialize ( ) ;
  23.     cout<<"ok";
  24.     cin.getline (postfix,80) ;
  25.     cout<<"ok";
  26. //    SetExpression (postfix) ;
  27.     puts(postfix);
  28.     strcpy(eval,postfix);
  29. //    m=Evaluate( );
  30.     printf("answer: %d", m );
  31.     return 0;
  32. }
  33.  
Oct 22 '06 #46
saraSS
69 New Member
yes it does not compile Im trying to get the line from this file so i'm doing the compilation and getting this
-bash-2.05b$ g++ hi.cpp
-bash-2.05b$ a.out hw2file2.txt
ok
only one ok the imput file is abcdefUUUUIabIa cIadIaeIafIUUUU =
and still nothing I dont know I am running the new version of the program
Oct 22 '06 #47
arne
315 Recognized Expert Contributor
yes it does not compile Im trying to get the line from this file so i'm doing the compilation and getting this
-bash-2.05b$ g++ hi.cpp
-bash-2.05b$ a.out hw2file2.txt
ok
only one ok the imput file is abcdefUUUUIabIa cIadIaeIafIUUUU =
and still nothing I dont know I am running the new version of the program
Ah, you tried to get the data from a file, not typing it in by hand? Then it's clear why you get no line :)

Try

-bash-2.05b$ a.out < hw2file2.txt

Note the '<' ...
Oct 22 '06 #48
saraSS
69 New Member
why is it different for this file with all my file I usually use only a.out hw2file2.txt?
Oct 22 '06 #49
arne
315 Recognized Expert Contributor
why is it different for this file with all my file I usually use only a.out hw2file2.txt?
Because you try to get the data via cin! The file content is redirected to your program by '<'. If you use
a.out hw2file2.txt
you pass only the file name as a parameter. You still have to open the file then. Different approach.

BTW, you can also use '>' to redirect the output of your program to another file.

Did you get the data now from the file?
Oct 22 '06 #50

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

Similar topics

1
12855
by: Booser | last post by:
// Merge sort using circular linked list // By Jason Hall <booser108@yahoo.com> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> //#define debug
7
13533
by: barias | last post by:
Although circular dependencies are something developers should normally avoid, unfortunately they are very easy to create accidentally between classes in a VS project (i.e. circular compile-time dependencies). But then I started wondering how "easy" it would be to similarly make a NON-RUNTIME circular dependency between (implicitly linked) DLLs. Indeed authors like John Lakos, who focus on compile/link-time dependencies (not run-time),...
3
7068
by: donnyma | last post by:
I have a problem that looks like it has not been discussed before in these groups. I have a simple SQLAgent job that runs sp_who (could be anything, but let's just say sp_who for this example). I have set the jobstep to write to an output file "T:\out.txt". If the job is owned by an admin, it runs fine and writes the output file. If it is owned by a non-admin user, it gets the following error msg: Warning: cannot write logfile...
12
15718
by: shivapadma | last post by:
please anyone tell me whether the following code works for checking the linked list is circular or not? address 0 address1 address2 | A|address1| |B|address2| |C|address0| | | | | ptr1 ptr2 A,B,C-are elements in list.
3
4147
by: Giampaolo Rodola' | last post by:
Hi there, I would like to know if such function would be correct for verifying if a link is broken and/or circular. def isvalidlink(path): assert os.path.islink(path) try: os.stat(path) except os.error: return 1
2
6434
by: morris11 | last post by:
I am trying to create a circular list that includes insert() , find() and remove() methodes. also a step() method that moves current along to the next link. I still need to display the list by breaking the circle at some arbitrary point to print it on the screen. Does anyone have an idea how to do that? import javax.swing.JOptionPane; public class CLL { public class Link { int item=0; Link next;
5
3406
by: =?Utf-8?B?Qm9i?= | last post by:
I have a table of dependencies and want to check to see if the dependencies cause a circular reference. Any sugesstions on how to do this using c#. Example, ID DependsOnID 1 2 1 4 2 3 3 1 (circular reference)
0
2838
balabaster
by: balabaster | last post by:
Hi, I have a couple of tables: Units( Unit_PKey Int Identity(1,1) Primary Key, Unit_Name nvarchar(8), Unit_Description nvarchar(32) )
5
1430
by: Muzammil | last post by:
i have problem with this operator "+" in doubly circular link list.(i think i have problem with return type). error is of instantiate error.(mean type dismatch) if any one can help me please reply. template <class T> DoublyCircularLinkList<TDoublyCircularLinkList<T>:: operator + (const DoublyCircularLinkList& rhs) { if (head==0 && rhs.head==0) {
0
9970
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9810
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11207
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10794
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10896
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10443
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9612
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
4652
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4251
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.