Untitled
unknown
plain_text
3 years ago
1.8 kB
8
Indexable
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define MAX_STRING_LENGTH 1024
//////////////// DO NOT CHANGE ANY OF THE CODE BELOW HERE //////////////////
void make_alternating(char string[MAX_STRING_LENGTH]);
int main (void) {
//You don't need to understand this code to complete the exercise.
//Scans in a string from the user.
char buffer[MAX_STRING_LENGTH];
fgets(buffer, MAX_STRING_LENGTH, stdin);
// Runs your function
make_alternating(buffer);
// Prints resulting string.
printf("%s", buffer);
return 0;
}
//////////////// DO NOT CHANGE ANY OF THE CODE ABOVE HERE //////////////////
////////////////////////////////////////////////////////////////////////////
///////////////////// ONLY WRITE CODE BELOW HERE ///////////////////////////
////////////////////////////////////////////////////////////////////////////
// Modifies `string` so that the first letter is converted to lowercase,
// and the case of each following letter alternates.
// i.e. in the resulting string:
// the first letter is lowercase,
// second letter is uppercase,
// third letter is lower case,
// etc.
//
// e.g.: "Hello" -> "hElLo"
void make_alternating(char string[MAX_STRING_LENGTH]) {
int i = 0;
if(string[i] != ' '){
for(i = 0;string[i] != '\0';i++) {
if ((i%2) == 0) {
string[i] = tolower(string[i]);
} else
string[i] = toupper(string[i]);
}
}
}
// TODO: complete this function
////////////////////////////////////////////////////////////////////////////
///////////////////// ONLY WRITE CODE ABOVE HERE ///////////////////////////
////////////////////////////////////////////////////////////////////////////Editor is loading...