I couldn’t find which is the right format for ‘char *’ so I just tried every letter.
Two letters works: %s and %p
Meaning it will compile and run the program. But it just prints random stuff:
%s gives:
argv[1][i] is the same as letter, so argv[0] would be the name of your script, argv[1] holds all the values you pass as arguments to the script.
argc holds the number of arguments, script name included.
In that script the first if checks if the number of arguments is not equal to 2, because the program expects exactly 2 arguments: the name of the script at position [0] and a string made of 1 or more characters at position 1. Try doing ./ex10 erhdy grt - you have 3 arguments, you’ll get an error. Try doing ./ex10, you have only 1 argument at position [0], you’ll get an error.
If you do smth like ./ex10 ghyrb, you’re good. So the ghyrb int he last example is the second argument at position [1] and now you check each character in it to see if it’s a vowel or not.(You remember a string in C is a list of characters, so you can access each character in it by its index.)
g in ghyrb is at position [0] of the string. So you have argv[1][0] == g
Can you see it now?
You use ‘%s’ to print a whole string. So %s is for argv[i], and %c is for argv[i][1]. Try that, @io_io has a lot of good info but I think that little bit was missing.
here’s the relevant part of the source code for the above output:
#include <stdio.h>
int main(int argc, char *argv[])
{
int i = 0;
//go through each string in argv
//why am I skipping argv[0]?
for (i = 1; i < argc; i++) {
printf("arg %d:\t%s,\targc:\t%d, argv:\t%s\n", i, argv[i], argc, argv[i]);
I think we can close this session now. Thank you @io_io .Thank you @zedshaw