Codice PHP:
#include <stdio.h>
#include <string.h>
void get_name(char *name,char path[3000])
{
char temp[1000];
char carattere;
char *p;
int lunghezza, i, j=0;
strcpy(temp, path);
printf("temp: %s\n", temp);
lunghezza = strlen(temp);
printf("lunghezza :%i\n", lunghezza);
for (i=0; i < lunghezza; i++)
{
carattere = temp[i];
if (carattere=='/')
{
j++;
}
}
printf("numero di /: %i\n",j);
p = strtok(temp,"/");
printf("p: %s\n",p);
printf("temp: %s\n", temp);
for (i=0; i<j; i++)
{
strcpy(temp, p);
p = strtok(NULL, "/");
printf("%s\n", temp);
}
j=0;
/****************************
* qui devo mettere temp in name
*********************/
strcpy(name,temp);
printf("nome file dentro: %s\n", name);
}
/********************
* MAIN
********************/
main()
{
char *name=NULL;
get_name(name,"/home/prova/ciao.png");
printf("nome file fuori: %s\n", name);
}
Ho spezzato il nome del file tramite / e arrivo ad avere in temp il nome del file dal percorso.
come faccio a metterlo in name?
la variabile stringa che ho nel main?
la strcpy mi da segmentation fault.