#include <iostream>
#include<string>
using namespace std;
class substr
{
public:
void getsubstr(char* b, char* db)
{
char* stpos = strstr(db,"gi|");
int pos = db-stpos;
char* end = strstr(db,"|ref");
int endpos = abs(db-end);
b= new char[endpos-pos+2];
int i=pos+3;
for(;i<endpos;i++)
{
*b++=*(db+i);
}
*(b+i)='\0';
}
};
int main()
{
substr* s;
char* b;
char* db= "gi|71772593|ref|NM_001032.3|";
s->getsubstr(b,db);
cout<<b<<endl;
delete s;
}
/*Error Message
)t$1EDE
D$$9uރ
[^_]Ë$ÐUSt1Ћu[]ÐUS
*** glibc detected *** ./a.out: free(): invalid pointer: 0xb7f81dc0 ***
*/
man4ish
0
Newbie Poster
Recommended Answers
Jump to Post1. Use code tag to present your snippets:
[code=cplusplus] your code[/code]
2. Stop this terrible source alignment! Use indentation.
3. You declare uninitialized pointer to substr class object (s). But where is the object?
4. Your substr class contains the only (and very dangerous) member function. It's a very …
All 3 Replies
Reply to this topic
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.