Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    [C] come dividere stringa in base a un carattere

    ciao,
    come faccio a dividere in C una stringa in base al carattere "." ?
    codice:
    esempio:      char stringa[]="ciao.roberto.come.va";
    Vorrei avere un vettore vettore di 4 posizioni contenente:
    codice:
    ciao
    roberto
    come 
    va
    grazie

  2. #2
    Un vettore di 4 posizioni....

    Ti piacciono i puntatori?

    codice:
            char str[] = "ciao.roberto.come.va";
    	char *i = str;
    	char **moreStr = NULL;
    
    	int nDot = 0;
    
    	while( *i++ != '\0' )
    	{
    		if( *i == '.' )
    			++nDot;
    	}
    
    	moreStr = (char **) malloc( (nDot+1) * sizeof(char *) );
    
    	if( moreStr != NULL )
    	{
    		int pos = 0;
    		i = str;
    		moreStr[ pos++ ] = i;
    
    		while( *i++ != '\0' )
    		{
    			if( *i == '.' )
    			{
    				*i = '\0';
    				moreStr[ pos++ ] = ++i;
    			}
    		}
    
    		stampa( moreStr, nDot+1 );  // FAI QUELLO CHE VUOI....
    
    		free( moreStr );
    	}

    Fracty - The Fractal Generator



    If you cannot choose a concise name that expresses what the method does, it is possible that your method is attempting to perform too many diverse tasks.

  3. #3
    grazie mille!!! sei il mio nuovo idolo!!! non sai quante parole ho tirato fino ad ora!!

    grazie grazie grazie!

  4. #4



    Figurati
    Fracty - The Fractal Generator



    If you cannot choose a concise name that expresses what the method does, it is possible that your method is attempting to perform too many diverse tasks.

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 © 2024 vBulletin Solutions, Inc. All rights reserved.