I have a relatively simple problem. A user is supposed to run the program,type in a message of 30 characters or less and then the case of the individual letters of the messages will be toggled.(lowercase letters will be made upercase and vice versa). Everything is fine except for the part of changing the case. I am supposed to use a pointer to a char in an array and pass it as a function argument to toggle_case. Please assist me on how to achieve this. Here is the code.
#include <stdio.h>
#include <ctype.h>
#include <string.h>
void read_message(char *message, int *message_size);
void toggle_case(char *character);
void count_cv(char* message);
int main() {
char message[30];
int message_size;
char *message_pointer;
message_pointer = message;
read_message(message, &message_size);
int i = 0;
for(i =0; i<30; i++){
toggle_case(&message_pointer[i]);
}
printf("New string: %s",message);
return 0;
}
void read_message(char *message, int *message_size){
printf("Enter your string (maximum 30 characters): ");
fgets(message, 30, stdin);
}
void toggle_case(char *character){
//check if character is a letter
if (isalpha(*character)) {
//Check if the character is upper case
if(isupper(*character)){
//convert the character to lower case
tolower(*character);
} else {
//Check if the character is lower case
//convert the character to upper case
toupper(*character);
}
}
}
void count_cv(char* message){
}
toggle_case. If that is your problem, then either assign the result withintoggle_caseor return a result for the caller to assign.message_sizedoesn't appear to be used at all...