//Revision Lecture 17: Strings //Sasha Vassar Week10 //Problem 2: Remove all characters in a string except for letters of the //alphabet (read the string from standard input) //Can you now read in from command line and do this? #include #include #include #define MAX 1000 int main (int argc, char *argv[]) { /*char line[MAX]; printf("Enter a string: "); fgets(line, MAX, stdin); // he9llo // hello */ //isalpha (if it is betwee a and z or A and Z) int i = 0; //argc = how many arguments there are on the line // while (counter < argc) //counter = 1 while (argv[1][i] != '\0') { int j = i; if (!isalpha(argv[1][j])){ // get rid of it and shift everything back by one index // he9llo // line[2] = 9 // line[2] = l // line[3] = l // line[4] = o while (argv[1][j] != '\0') { argv[1][j] = argv[1][j + 1]; j++; } argv[1][j]= '\0'; } i++; } printf("Output string is: %s\n", argv[1]); return 0; }