Discussione: [C] gestione stringhe
View Single Post
Old 16-02-2009, 19:03   #5
xHombrex
Member
 
Iscritto dal: Jul 2005
Messaggi: 45
OK credo che userņ questa funzione read_string() in questo modo :

Codice PHP:
char *read_string()
{
     
    
int eof 0
    
char *line;
    
int i16;
    
char c;
    if (
eof) {
        return 
NULL;
    }
    
line malloc(sizeof(char) * s);
    for (
01i++) {
        if (
>= s) {
            
*= 2;
            
line realloc(lines);
        }
        
getchar();    
        switch (
c) {
            case 
'\n':
                
line[i] = '\0'
                return 
line;
            case 
EOF:
                
eof 1;
                if (
== 0) return NULL;
                
line[i] = '\0'
                return 
line;
            default: 
                
line[i] = c; break;
        }
    }






Codice PHP:
while((stringa read_string()) != NULL);
   
  
   
   
printf("%s",stringa);
   
   
   
token1 strtok(stringa" ");
   
token2 strtok(stringa" ");
   
token3 strtok(stringa"");
   
        
printf("%s \n",token1);
        
printf("%s \n",token2);
        
printf("%s \n",token3); 


il problema č che ora perņ non mi stampa nulla!rimane sempre in attesa che inserisca input e in pratica non termina mai...dove sbaglio?
xHombrex č offline   Rispondi citando il messaggio o parte di esso