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.
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.
Solution
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_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 str[100];
printf("Enter a string to reverse: ");
gets(str);
reverse_string(str);
printf("Reverse of the string: %s\n", str);
printf("Uppercase of the first letter of the reversed word: %c\n", toupper(str[0]));
return 0;
}
This program works by swapping the characters at the beginning and end of the string, and then moving the pointers towards the center of the string. The toupper function is used to convert the first character of the reversed string to uppercase.
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)
Reversing a string in C is a fundamental operation that involves rearranging the characters in a string so that the last character becomes the first, the second-to-last character becomes the second, and so on.
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.