hello, im stuck in a simple loop,i dont know why this doesnt give me the expected result! im really really confused!
please help find the problem.
Code:
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
string str = "sum: 5";
char * cstr;
char currentcharacter;
char strvalue[15];
cstr = new char [str.size()+1];
strcpy (cstr, str.c_str());
char * ptr;
int found = str.find(':');
int value=0,cnt=0;
while( cstr[found]!='\0')
{
currentcharacter = cstr[ found];
if ( (isspace(currentcharacter) ))
{
found++;
continue;
}
ptr[ found] = cstr[ found];
found++;
}
value = atoi(ptr);
cout<<ptr<<endl;
cout<<value+10;
system("PAUSE");
return EXIT_SUCCESS;
}
the ptr gets filled with garbage characters . !(or may be it doesnt ever get filled)