I know this is fairly basic, but I’m still stuck.
So I have a function that needs to take in a variable n, so this is my main function
int main(int argc, char* argv){
sort(argv[1]);
}
And I’m calling the program like this:
./sort 4 <text.txt
But the number 4 doesnt get recognized or passed into the function. What am I doing wrong? I know that argv[0] should hold the name of program itself and each one from there on should hold the arguments.
You should try to print them all.
Running that code with
./a.out 4 < /somefilegives me:Eventually you’ll have to remember that the ‘4’ is a pointer to an array of characters, and you might have to parse it into an integer.