Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 12
  1. #1

    int main(int argc, char *argv[])..

    Salve, se scrivo:

    int main(int argc, char *argv[]){
    printf("%s",argv[1]);
    return(0);
    }

    In output leggo il primo parametro che scrivo...
    Ma se io non avessi il numero dei parametri definiti?

    Faccio un esempio:

    codice:
    [michele@localhost c]$ ./ciao questa è una bella giornata!
    Vorrei che il programma mi scrivesse:

    questa è una bella giornata!

    E' possibile farlo?

  2. #2
    Utente di HTML.it L'avatar di alexmaz
    Registrato dal
    May 2001
    Messaggi
    972
    argc contiene il numero di parametri passati alla riga di comando. E' sempre almeno 1 perchè argv[0] è il nome del programma.
    The individual has always had to struggle to keep from being overwhelmed by the tribe. If you try it, you will be lonely often, and sometimes frightened. But no price is too high to pay for the privilege of owning yourself.

  3. #3

    Lo so..

    Si lo sò...
    Ma forse non mi sono spiegato bene:

    Se io scrivo argv[1] è la prima parola...

    Se io scrivo argv[2] è la seconda parola...

    Se io scrivo argv[3] è la terza parola...

    Io vorrei avere un argv che me le scrive tutte a partire da una specificata.

    Esiste questa possibilità?

    Ripeto:

    ./ciao 1 2 3

    Risultato:

    1 2 3

    Oppure:

    ./ciao 1 2 3 4 5 6 7

    Risultato:

    1 2 3 4 5 6 7

  4. #4
    Utente di HTML.it L'avatar di alexmaz
    Registrato dal
    May 2001
    Messaggi
    972
    la risposta l'avevi gia, ma cmq...

    codice:
    int main(int argc, char *argv[]){
    int i;
    for(i = 1; i < argc; i++)
    	printf("%s\n", argv[i]);
    return(0);
    }
    The individual has always had to struggle to keep from being overwhelmed by the tribe. If you try it, you will be lonely often, and sometimes frightened. But no price is too high to pay for the privilege of owning yourself.

  5. #5
    nome_programma "1 2 3 4 5 6 7 8 9 10"

    metti ogni parametro tra doppi apici!!!

    parametro1 = 1 2 3 4 5 6 7 8 9 10
    ...Terrible warlords, good warlords, and an english song

  6. #6
    ...cmq la risposta più corretta è quella che ti ha dato alexmaz
    ...Terrible warlords, good warlords, and an english song

  7. #7
    Utente di HTML.it L'avatar di alexmaz
    Registrato dal
    May 2001
    Messaggi
    972
    Originariamente inviato da Johnny_Depp
    nome_programma "1 2 3 4 5 6 7 8 9 10"

    metti ogni parametro tra doppi apici!!!

    parametro1 = 1 2 3 4 5 6 7 8 9 10
    perchè hai cancellato il tuo secondo post?
    The individual has always had to struggle to keep from being overwhelmed by the tribe. If you try it, you will be lonely often, and sometimes frightened. But no price is too high to pay for the privilege of owning yourself.

  8. #8
    :gren: i n d o v i n a :quote:
    ...Terrible warlords, good warlords, and an english song

  9. #9
    Utente di HTML.it L'avatar di alexmaz
    Registrato dal
    May 2001
    Messaggi
    972
    Originariamente inviato da Johnny_Depp
    :gren: i n d o v i n a :quote:
    non lo so
    The individual has always had to struggle to keep from being overwhelmed by the tribe. If you try it, you will be lonely often, and sometimes frightened. But no price is too high to pay for the privilege of owning yourself.

  10. #10
    perchè (sarà colpa della digestione :gren: )

    avevo scritto una cavol***
    ...Terrible warlords, good warlords, and an english song

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.