virusso80
04-10-2010, 16:24
Ciao a tutti.
Il mio problema è forse stupido ma non riesco a uscirne. ho creato un metodo che data una stringa del formato stringa1:stringa2 crea le due sottostringe e le ritorna in due variabili separate.
ho fatto nel seguente modo:
#include <string.h>
#include <stdio.h>
int get_file_destpath(char *filename, char *destpath, char *buffer)
{
destpath = strstr(buffer, ":");
if(destpath == NULL) return -1;
destpath++; //skip the ':'
strncpy(filename, buffer, destpath - buffer -1);
printf("filename=%s, destpath=%s", filename, destpath);
return 0;
}
int main()
{
char *s = "pippo:pluto";
char s1[256], s2 [256];
memset(s1, 0x00, 256);
memset(s2, 0x00, 256);
get_file_destpath(s1, s2, s);
printf("filename=%s, destpath=%s\n", s1, s2);
return 0;
}
perchè s1 c'è e s2 no? nel metodo tutto è invece stampato correttamente
spero in una vostra delucidazione!
Grazie anticipatamente!
Il mio problema è forse stupido ma non riesco a uscirne. ho creato un metodo che data una stringa del formato stringa1:stringa2 crea le due sottostringe e le ritorna in due variabili separate.
ho fatto nel seguente modo:
#include <string.h>
#include <stdio.h>
int get_file_destpath(char *filename, char *destpath, char *buffer)
{
destpath = strstr(buffer, ":");
if(destpath == NULL) return -1;
destpath++; //skip the ':'
strncpy(filename, buffer, destpath - buffer -1);
printf("filename=%s, destpath=%s", filename, destpath);
return 0;
}
int main()
{
char *s = "pippo:pluto";
char s1[256], s2 [256];
memset(s1, 0x00, 256);
memset(s2, 0x00, 256);
get_file_destpath(s1, s2, s);
printf("filename=%s, destpath=%s\n", s1, s2);
return 0;
}
perchè s1 c'è e s2 no? nel metodo tutto è invece stampato correttamente
spero in una vostra delucidazione!
Grazie anticipatamente!