repost: leak using c++ string

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Closed Thread

Join Date: Jan 2005
Posts: 2
Reputation: danissl is an unknown quantity at this point 
Solved Threads: 0
danissl danissl is offline Offline
Newbie Poster

repost: leak using c++ string

 
0
  #1
Jan 10th, 2005
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 ]

  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. }
Quick reply to this message  
Join Date: Dec 2003
Posts: 2,414
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Solved Threads: 123
Team Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

Re: repost: leak using c++ string

 
0
  #2
Jan 10th, 2005
Why the repost? Just keep posting in the other thread.
Alex Cavnar, aka alc6379
Quick reply to this message  
Closed Thread

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1860 | Replies: 1
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC