#Cannot find error in code

7 messages · Page 1 of 1 (latest)

drifting salmon
#
#include <stdio.h>

#define MAX_STRING_LENGTH 50


void make_alternating(char string[MAX_STRING_LENGTH]);

int main (void) {
    char string[MAX_STRING_LENGTH];
    fgets(string, MAX_STRING_LENGTH, stdin);

    make_alternating(string);

    return 0;
}

void make_alternating(char string[MAX_STRING_LENGTH]) {
    int array_index = 0;
    int counter_of_letter = 0;

    while (string[array_index] != '\0') {
        if (string[array_index] >= 65 && string[array_index] <= 90) {
            if (counter_of_letter % 2 == 0) {
                printf("%c", string[MAX_STRING_LENGTH] + 32);
                counter_of_letter = counter_of_letter + 1;
            }
            else {
                printf("%c", string[MAX_STRING_LENGTH]);
                counter_of_letter = counter_of_letter + 1;
            }
        }
        else if (string[array_index] >= 97 && string[array_index] <= 122) {
            if (counter_of_letter % 2 == 0) {
                printf("%c", string[MAX_STRING_LENGTH]);
                counter_of_letter = counter_of_letter + 1;
            }
            else {
                printf("%c", string[MAX_STRING_LENGTH] - 32);
                counter_of_letter = counter_of_letter + 1;
            }
        }
        else {
            printf("%c", string[MAX_STRING_LENGTH]);
        }
        array_index = array_index + 1;
    }

}

Im trying to create a program that alternates lowercase and uppercase of letters as seen in the image i provided. Im not getting it to do what i want and i can't find the error ;-;

rare slateBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

faint lagoon
#

check each of your printf statements carefully

drifting salmon
#

lmao

#

oh

#

wrong index

#

!solved