Pagina 2 di 2 primaprima 1 2
Visualizzazione dei risultati da 11 a 17 su 17

Discussione: Array e stringhe in C

  1. #11
    Se potessi volentieri, ti farei compagnia...
    Speriamo che riesca a hackerare qualche DB bancario cosė invece del biglietto ti regalo la casa...
    CC,
    BB.....

  2. #12
    Purtroppo devo ancora scassarti....

    Se questo codice dovessi metterlo all'interno di una funzione e farmi restituire l'array come potrei fare?

    codice:
    char string[] = "From: JACOPO \r\n X-Mailer: WeB \r\n";
    char seps[]   = "\r\n";
    char *token;
    char *dest[255];
    int counter,i;
    				
    printf( "%s\n\nTokens:\n", string );
    token = strtok( string, seps );
    counter = 0;
      while( token != NULL )
      {
        dest[counter] = token; //array che mi serve
        printf( "%s\n", token );
        token = strtok( NULL, seps );
        counter++;
      }

  3. #13
    Utente di HTML.it L'avatar di floyd
    Registrato dal
    Apr 2001
    Messaggi
    3,837
    *char[] getMaCheNeSo(char *string) {
    // code
    return dest;
    }

  4. #14
    Quindi dovrei scrivere una cosa di questo tipo ???

    *char[] log_header(char *string)
    {
    char seps[] = "\r\n";
    char *token;
    char *dest[255];
    int counter;

    token = strtok( string, seps );
    counter = 0;
    while( token != NULL )
    {
    dest[counter] = token;
    token = strtok( NULL, seps );
    counter++;
    }
    return dest;
    }

  5. #15
    Utente di HTML.it L'avatar di floyd
    Registrato dal
    Apr 2001
    Messaggi
    3,837
    credo
    ma dato che non scrivo in C da un sacco di tempo

  6. #16
    Hai idea del perchč il compilatore gcc mi restituisca un errore del tipo : "Segmentation fault" ?

  7. #17
    Utente di HTML.it L'avatar di floyd
    Registrato dal
    Apr 2001
    Messaggi
    3,837
    ho provato con questo
    codice:
    char** tokenizza(const char *stringa) {
    	char *s = strchr(stringa, '\n');
    	char *str1;
    	int numeroDiToken = 1;
    	while (s != NULL) {
    		numeroDiToken++;
    		s = strchr(s+1, '\n');
    	}
    
    
    	char *dest[numeroDiToken];
    	int c = 0;
    	// primo token
    	str1 = strtok(stringa, "\n");
    	if (str1 != NULL) {
    		dest[c++] = str1;
    	}
    	while (1) {
    		// successivo token
    		str1 = strtok(NULL, "\n");
    
    		if (str1 == NULL) {
    			printf("Tokenizing complete\n");
    			break;
    		}
    		dest[c++] = str1;
    	}
    	return dest;
    }
    compila e viene eseguito, il fatto č che il valore di ritorno č buffo
    dentro la funzione se scrivo dest[c] quando gli assegno la stringa mi mostra quello che voglio, fuori dalla funz fa casino

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.