I'm used to other languages. Now I'm in C. I have filled in a "string" character to character and when printing it, nothing appears, I do not know if it is because of the null terminator or for what reason. I would appreciate help. I just want to delete the path from a complete path and I want to keep the file and the extension of the file:
#include <stdio.h>
char linea[50]="c:\pepe\resul.exe";
char nombrefich[50]="";
int x,cantidad,i;
void main()
{
printf("Cadena inicial: %s\n",linea);
x=strlen(linea);
cantidad=1;
do {
x--;
cantidad++;
} while (linea[x]!='\');
x++;
i=1;
for(x=x;x<strlen(linea);x++)
{
//printf("%c",linea[x]);
nombrefich[i]=linea[x];
i++;
}
nombrefich[i]='#include <stdio.h>
char linea[50]="c:\pepe\resul.exe";
char nombrefich[50]="";
int x,cantidad,i;
void main()
{
printf("Cadena inicial: %s\n",linea);
x=strlen(linea);
cantidad=1;
do {
x--;
cantidad++;
} while (linea[x]!='\');
x++;
i=1;
for(x=x;x<strlen(linea);x++)
{
//printf("%c",linea[x]);
nombrefich[i]=linea[x];
i++;
}
nombrefich[i]='%pre%';
printf("Resultado final: %s\n",nombrefich);
}
';
printf("Resultado final: %s\n",nombrefich);
}