944,214 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2023
  • C++ RSS
Jan 10th, 2005
0

repost: leak using c++ string

Expand Post »
Hi

part of a homework .
I got a lek in this code when using string for parsing
I do not 'have' to use string.. it just seemed comfortable
input is of the form 2*x**6+term+term+...
[ full source code availabe if that helps ]

C++ Syntax (Toggle Plain Text)
  1. #include <string>
  2.  
  3. //possibly causes memleak - try switching to c string
  4. Polynomial::Polynomial(char* poly):_head(NULL){
  5. string s = poly;
  6. s = "+" + s;
  7.  
  8. double cof;
  9. int exp;
  10. int chars;
  11.  
  12. unsigned int index = 0;
  13. while (index != string::npos){
  14. s = s.substr(index+1);
  15. chars = sscanf(s.c_str(),"%lf *x** %d",&cof,&exp);
  16. if (chars == 2){
  17. insert(cof,exp);
  18. } else {
  19. cout<<"Wrong Format!";
  20. break;
  21. }
  22. index = s.find_first_of("+",index);
  23. }
  24. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
danissl is offline Offline
2 posts
since Jan 2005
Jan 10th, 2005
0

Re: repost: leak using c++ string

Why the repost? Just keep posting in the other thread.
Team Colleague
Reputation Points: 186
Solved Threads: 147
Cookie... That's it
alc6379 is offline Offline
2,519 posts
since Dec 2003

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in C++ Forum Timeline: Change Counter
Next Thread in C++ Forum Timeline: Help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC