954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

repost: leak using c++ string

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 ]

#include <string>

//possibly causes memleak - try switching to c string
Polynomial::Polynomial(char* poly):_head(NULL){
	string s = poly;
	s = "+" + s;

	double cof;
	int exp;
	int chars;

	unsigned int index = 0;
	while (index != string::npos){
		s = s.substr(index+1);
		chars = sscanf(s.c_str(),"%lf *x** %d",&cof,&exp);
		if (chars == 2){
			insert(cof,exp);
		} else {
			cout<<"Wrong Format!";
			break;
		}
		index = s.find_first_of("+",index);
	}
}
danissl
Newbie Poster
2 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

Why the repost? Just keep posting in the other thread.

alc6379
Cookie... That's it
Team Colleague
2,820 posts since Dec 2003
Reputation Points: 186
Solved Threads: 147
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You