I'm doing a small IDE in c ++ and I'm having trouble getting the name of a file. ex: the full path of the file is "keywords // cplusplus.txt" however the file name is "cplusplus.txt". So I wrote a function to get the real name.
char* Io::GetRealName(int file)
{
char* full_name=GetName(file);
int last_bar=0;
for(int i=0;i<strlen(full_name);i++)
{
if(full_name[i]=='/')
{
last_bar=i+1;
}
}
char* real_name=(char*) malloc((strlen(full_name)-last_bar)*sizeof(char));
memcpy (real_name,full_name+last_bar,strlen(full_name));
real_name[strlen(full_name)-last_bar]='char* Io::GetRealName(int file)
{
char* full_name=GetName(file);
int last_bar=0;
for(int i=0;i<strlen(full_name);i++)
{
if(full_name[i]=='/')
{
last_bar=i+1;
}
}
char* real_name=(char*) malloc((strlen(full_name)-last_bar)*sizeof(char));
memcpy (real_name,full_name+last_bar,strlen(full_name));
real_name[strlen(full_name)-last_bar]='%pre%';
return real_name;
}
';
return real_name;
}
The GetName (int) function takes the full path of the file. I do not know what's wrong, because when I finished the function was working, however, after a while it started to crash and now sometimes crashes and some not. Does anyone know what's wrong? The pointers maybe?