|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Member
Iscritto dal: Oct 2005
Città: Milano
Messaggi: 153
|
[C] perchè non mi conserva il valore? [RISOLTO]
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: Codice:
#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;
}
spero in una vostra delucidazione! Grazie anticipatamente! Ultima modifica di virusso80 : 04-10-2010 alle 17:29. |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Apr 2010
Città: Frosinone
Messaggi: 416
|
Codice:
destpath = strstr(buffer, ":"); |
|
|
|
|
|
#3 |
|
Member
Iscritto dal: Oct 2005
Città: Milano
Messaggi: 153
|
è vero!!
ho risolto definendo un puntatore char* per strstr e poi copio successivamente! grazie mille! |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 23:48.



















