How do main function entries in C work?

1

I've always used the main function as follows, creating other functions:

int main() {
    .
    .
    .
    return 0;
}

How do entries work in the main function?

int main(int argc, char **argv){

We have a variable and a char, right? So I have to provide these values before running the program, right?

You could, in shell, execute the following line, for example:

./bin/programa -e ./data/entrada.txt  -s ./data/saida.net

Correct?

    
asked by anonymous 20.03.2018 / 21:47

1 answer

3

You have an array of strings (char ** argv) of integer size (int argc). It is important to note that the parameter of position 0 is the name of the program itself, and the next are the parameters passed in the command line so your example would give us the following:

argv[0] = "./bin/programa"
argv[1] = "-e"
argv[2] = "./data/entrada.txt"
argv[3] = "-s"
argv[4] = "./data/saida.net"
    
20.03.2018 / 21:51