Hot answers tagged

3

If I understand your question correctly, and it's "what is the role of argc" the answer is that we need it to know how many arguments were passed to main from the command line. So if the command was ./hello-4 Zamyla we have argc == 2 and argv[0] == "./hello-4" and argv[1] == "Zamyla". Without argc you wouldn't know the length of argv.


2

Your problem is isalpha(argv[1]) isalpha takes a single character as input. argv[1] is a string of multiple characters, not a character. You cannot apply isalpha to an entire string. It causes a seg fault. If this answers your question, please accept this answer to remove the question from the unanswered question pool. Let's keep up on forum housekeeping. ...


1

Your values are like +---+---+---+---+ |min|max|mid|<>=| +---+---+---+---+ | 0|999|499| < | | 0|498|249| < | | 0|248|124| < | | 0|123| 61| < | | 0| 60| 30| < | | 0| 29| 14| < | | 0| 13| 6| < | | 0| 5| 2| < | | 0| 1| 0| > | | 1| 1| 1|< >| +---+---+---+---+ the value you searched for is between the ...


1

in case we have a single element left in the array, max and min would be equal. the midpoint is calculated, and we check whether array[midpoint] is equal to the value we're looking for. if the previous condition is not true, namely array[midpoint] is NOT equal to the value we're looking for, the algorithm still proceeds further and either sets max to a ...


1

You also need to print a new line \n after the final letter. So after your for loop has ended just print a new line.


Only top voted, non community-wiki answers of a minimum length are eligible