wingnut2626
December 24th, 2013, 12:41 AM
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
int argument, letter_position, number_of_characters;
char current_character;
for(argument = 1; argument <= argc; argument++){
number_of_characters = strlen(argv[argument]);
printf("%d number of characters debug", number_of_characters);
getchar();
for(letter_position = 0; argv[argument][letter_position] != '\0'; letter_position++){
printf("starting loop, position %d", letter_position + 1);
getchar();
current_character = argv[argument][letter_position];
if(current_character == 'A' || 'a'){
printf("%d letter of %d argument is A\n", letter_position + 1, argument);
}
else if(current_character == 'E' || 'e'){
printf("%d letter of %d argument is E\n", letter_position + 1, argument);
}
else if(current_character == 'I' || 'i'){
printf("%d letter of %d argument is I\n", letter_position + 1, argument);
}
else if(current_character == 'O' || 'o'){
printf("%d letter of %d argument is O\n", letter_position + 1, argument);
}
else if(current_character =='U' || 'u'){
printf("%d letter of %d argument is U\n", letter_position + 1, argument);
}
}
}
return 0;
}
Basically im trying to filter through each letter of each argument and spit out the vowels. I even included debug statements, cannot for the life of me understand why this is the output:
./test13 this is a string
4 number of characters debug
starting loop, position 1
1 letter of 1 argument is A
starting loop, position 2
2 letter of 1 argument is A
starting loop, position 3
3 letter of 1 argument is A
starting loop, position 4
4 letter of 1 argument is A
2 number of characters debug
starting loop, position 1
1 letter of 2 argument is A
starting loop, position 2
2 letter of 2 argument is A
1 number of characters debug
starting loop, position 1
1 letter of 3 argument is A
6 number of characters debug
starting loop, position 1
1 letter of 4 argument is A
starting loop, position 2
2 letter of 4 argument is A
starting loop, position 3
3 letter of 4 argument is A
starting loop, position 4
4 letter of 4 argument is A
starting loop, position 5
5 letter of 4 argument is A
starting loop, position 6
6 letter of 4 argument is A
zsh: segmentation fault ./test13 this is a string
what is going on?
#include <string.h>
int main(int argc, char *argv[])
{
int argument, letter_position, number_of_characters;
char current_character;
for(argument = 1; argument <= argc; argument++){
number_of_characters = strlen(argv[argument]);
printf("%d number of characters debug", number_of_characters);
getchar();
for(letter_position = 0; argv[argument][letter_position] != '\0'; letter_position++){
printf("starting loop, position %d", letter_position + 1);
getchar();
current_character = argv[argument][letter_position];
if(current_character == 'A' || 'a'){
printf("%d letter of %d argument is A\n", letter_position + 1, argument);
}
else if(current_character == 'E' || 'e'){
printf("%d letter of %d argument is E\n", letter_position + 1, argument);
}
else if(current_character == 'I' || 'i'){
printf("%d letter of %d argument is I\n", letter_position + 1, argument);
}
else if(current_character == 'O' || 'o'){
printf("%d letter of %d argument is O\n", letter_position + 1, argument);
}
else if(current_character =='U' || 'u'){
printf("%d letter of %d argument is U\n", letter_position + 1, argument);
}
}
}
return 0;
}
Basically im trying to filter through each letter of each argument and spit out the vowels. I even included debug statements, cannot for the life of me understand why this is the output:
./test13 this is a string
4 number of characters debug
starting loop, position 1
1 letter of 1 argument is A
starting loop, position 2
2 letter of 1 argument is A
starting loop, position 3
3 letter of 1 argument is A
starting loop, position 4
4 letter of 1 argument is A
2 number of characters debug
starting loop, position 1
1 letter of 2 argument is A
starting loop, position 2
2 letter of 2 argument is A
1 number of characters debug
starting loop, position 1
1 letter of 3 argument is A
6 number of characters debug
starting loop, position 1
1 letter of 4 argument is A
starting loop, position 2
2 letter of 4 argument is A
starting loop, position 3
3 letter of 4 argument is A
starting loop, position 4
4 letter of 4 argument is A
starting loop, position 5
5 letter of 4 argument is A
starting loop, position 6
6 letter of 4 argument is A
zsh: segmentation fault ./test13 this is a string
what is going on?