Knowee
Questions
Features
Study Tools

Write a program in C to print a string in reverse using a character pointer. Also print the uppercase of the first letter of the reversed word. Sample Input word Sample Output drow D

Question

Write a program in C to print a string in reverse using a character pointer.

Also print the uppercase of the first letter of the reversed word.

Sample Input

word

Sample Output

drow

D

🧐 Not the exact question you are looking for?Go ask a question

Solution 1

Sure, here is a simple C program that reverses a string using a character pointer and also prints the uppercase of the first letter of the reversed word.

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

void reverse(char *str) {
    char *end = str;
    char temp;

    // Find end of the string
    while(*end) {
        ++end;
    }
    --end;

    // Swap characters
    while(str < end) {
        temp = *str;
        *str = *end;
        *end = temp;
        str++;
        end--;
    }
}

int main() {
    char word[] = "word";

    // Reverse the string
    reverse(word);

    printf("%s\n", word);

    // Print the uppercase of the first letter
    printf("%c\n", toupper(word[0]));

    return 0;
}

This program first reverses the string by swapping the characters from the start and end of the string. Then it prints the reversed string. Finally, it prints the uppercase of the first letter of the reversed string using the toupper function from the ctype.h library.

This problem has been solved

Solution 2

Sure, here is a simple C program that accomplishes this:

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

void reverse_print(char *str) {
    int length = strlen(str);
    for(int i = length - 1; i >= 0; i--) {
        printf("%c", str[i]);
    }
    printf("\n%c", toupper(str[length - 1]));
}

int main() {
    char word[] = "word";
    reverse_print(word);
    return 0;
}

This program works as follows:

  1. It includes the necessary header files. stdio.h for input/output functions, string.h for string manipulation functions, and ctype.h for character manipulation functions.

  2. It defines a function reverse_print that takes a string as input. This function first calculates the length of the string using strlen. Then it uses a for loop to print the characters of the string in reverse order. After printing the reversed string, it prints the uppercase version of the first character of the reversed string using toupper.

  3. In the main function, it defines a string word and calls reverse_print with this string. The main function then returns 0 to indicate successful execution of the program.

This problem has been solved

Similar Questions

Write a program that takes a string of lowercase characters as input and prints it in uppercase, reversed.

Write a C program to find reverse of a string using pointers

Write a C function, which reverses a given string and returns a pointer to reversed string.char *reverse(char *str);

Write c function to reverse words in sentence (without using external arrays)

python program to reverse a string

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.