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 InputwordSample OutputdrowD

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 InputwordSample OutputdrowD

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

Solution

Sure, here is a simple C program that reverses a string and prints the first letter of the reversed string in uppercase:

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

void reverse_string(char* str) {
    int length, c;
    char *begin, *end, temp;

    length = strlen(str);
    begin  = str;
    end    = str;

    for (c = 0; c < length - 1; c++)
        end++;

    for (c = 0; c < length/2; c++) {        
        temp   = *end;
        *end   = *begin;
        *begin = temp;

        begin++;
        end--;
    }
}

int main() {
    char word[100];

    printf("Enter a word: ");
    scanf("%s", word);

    reverse_string(word);

    printf("Reversed word: %s\n", word);
    printf("First letter of reversed word in uppercase: %c\n", toupper(word[0]));

    return 0;
}

This program works as follows:

  1. It reads a word from the user.
  2. It reverses the word by swapping the characters at the beginning and end of the string, and then moving towards the center.
  3. It prints the reversed word.
  4. It converts the first letter of the reversed word to uppercase using the toupper function and prints it.

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.