Hej,
Natknalem sie na problem ktorego nie moge zrozumiec i rozwiazac... Otoz ponizsza funkcja find ma za zadanie zwrocic C string z danego parametru line tak dlugi dopoki nie dojdzie do znaku end. Problemem jest to ze zwracany C string oprocz wlasciwych liter zawiera tez jakies losowe znaki i nie mam pojecia jak sie ich pozbyc... Powinien zwrocic "file:" a zwraca "file:" + 2 znaki nie wiadomo skad ;/ Bylbym ogromnie wdzieczny za pomoc.
#include <iostream>
#include <string>
char * find( const char * line, int line_length, char end );
int main()
{
std::cout << find( "file: somefile", 19, ' ' );
}
char * find( const char * line, int line_length, char end )
{
char * old_data = new char[ line_length ];
char * new_data = NULL;
int counter = 0;
while( line[ counter ] != end && counter < line_length )
{
old_data[ counter ] = line[ counter ];
counter++;
}
new_data = new char[ counter ];
memcpy( new_data, old_data, counter );
if( counter < line_length )
return new_data;
else
return "false";
}