#include	<stdio.h>
#include	<ctype.h>

int alternate_caps(char string[]);
void display(int num, char str[], int changes);

#define MAX_COL 40

int
main()
{
	char	strings[][MAX_COL] = {
				"This is an array of CHARACTERS.",
				"tHiS Is aNoThEr aRrAy oF ChArAcTeRs.",
				"thIs sTrInG ReQuIrEs oNe cHaNgE"
				};
	int	i;

	for (i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) {
		int	changes = alternate_caps(strings[i]);
		display(i, strings[i], changes);
	}
	return 0;
}

int
alternate_caps(char str[]) {
	int	i = 0;
	int	changes = 0;
	
	while (str[i] != '\0') {
		if (i % 2 == 0) {
			/* Make characters located at even indices
			   upper case (if they aren't already) */
			if (islower(str[i])) {
				str[i] = toupper(str[i]);
				changes ++;
			}
		}
		else {
			/* Make characters located at odd indices
			   lower case (if they aren't already) */
			if (isupper(str[i])) {
				str[i] = tolower(str[i]);
				changes ++;
			}
		}
		++ i;
	}

	return changes;
}

void
display(int num, char str[], int changes)
{
	printf("string[%d] is \"%s\" (%d change%s)\n",
		num, str, changes, (changes == 1) ? "" : "s");
}
