UrbanPro

Learn C Language from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

How do I write code in C programming that will invert a string like "Welcome to programming" to “gnimmargorp ot emocleW”?

Asked by Last Modified  

Follow 13
Answer

Please enter your answer

void main() { char msg = "Welcome to Programming"; char str; int i = 0, j = 0; clrscr(); while (msg != '\0') { if (msg != ' ') { str = msg; j++; } else { str = '\0'; printf("%s", strrev(str)); printf(" "); ...
read more
void main() { char msg[] = "Welcome to Programming"; char str[10]; int i = 0, j = 0; clrscr(); while (msg[i] != '\0') { if (msg[i] != ' ') { str[j] = msg[i]; j++; } else { str[j] = '\0'; printf("%s", strrev(str)); printf(" "); j = 0; } i++; } str[j] = '\0'; printf("%s", strrev(str)); getch(); } read less
Comments

Trainer

You can use recursion to reverse a string.
Comments

Tutor

First, find the position of \0 in the string, and it will be the size of the string. Now run a for loop from (size-1) to 0 and copy the char at the index in a temp array of chars. That's it
Comments

Online Computer Trainer

#include"stdio.h" #include"string.h" int main() { char *str = "Welcome to programming"; int i,j,len,temp; len=strlen(str); for(i=0,j=len-1;i
Comments

Working as a Data Scientist in Bangalore, India

//Jaspreet Singh. Contact Detail:- 798633671.8 #include stdio.h //angular brackets not allowed in this website, you will have to add #include string.h //angular brackets not allowed in this website, you will have to add void reverse(char , int, int); int main() { char str1; int...
read more
//Jaspreet Singh. Contact Detail:- 798633671.8 #include stdio.h //angular brackets not allowed in this website, you will have to add #include string.h //angular brackets not allowed in this website, you will have to add void reverse(char [], int, int); int main() { char str1[20]; int size; printf("Enter a string to reverse: "); scanf("%s", str1); size = strlen(str1); reverse(str1, 0, size - 1); printf("The string after reversing is: %s\n", str1); return 0; } //Jaspreet Singh. Contact Detail:- 798633671.8 void reverse(char str1[], int index, int size) { char temp; temp = str1[index]; str1[index] = str1[size - index]; str1[size - index] = temp; if (index == size / 2) { return; } reverse(str1, index + 1, size); } //Jaspreet Singh. Contact Detail:- 798633671.8 read less
Comments

Tutor

void main() { int i, j, k; char str; char rev; printf("Enter a string\t"); scanf("%s", str); printf("The original string is %s\n", str); for(i = 0; str != '\0'; i++); { k = i-1; } for(j = 0; j <= i-1; j++) { rev = str; k--; } printf("The reverse...
read more
void main() { int i, j, k; char str[100]; char rev[100]; printf("Enter a string\t"); scanf("%s", str); printf("The original string is %s\n", str); for(i = 0; str[i] != '\0'; i++); { k = i-1; } for(j = 0; j <= i-1; j++) { rev[j] = str[k]; k--; } printf("The reverse string is %s\n", rev); getch(); } read less
Comments

void main() { char str="Welcome to Programming"; int i,l; clrscr(); l=strlen(str); for(i=0;i=0;i--) { printf("%c",a); } }
Comments

Dissertation Helper

You are having four options to write the program. 1. you can make your own reverse function by use of swap. 2. you can use built in reverse function 3. you can write your own reverse function using strlen() 4. using pointer and array if string is constant string
Comments

CodeGeeks

#include "stdio.h" #include "string.h" int main() { char str="Welcome to programming"; int i=strlen(str); for (; i >= 0; i--) printf("%c", str); printf("\n"); return 0; }
Comments

Tutor

#include"stdio.h" void main() { char str; int i, j, temp, len=0; clrscr(); printf("Enter String "); gets(str); len = strlen(str); for(i=0, j=len-1; i < len/2; i++, j--) { temp = str; str = str; str = temp; } printf("\nReverse string is :\n%s", str); getch(); }
Comments

View 10 more Answers

Related Questions

How can I make my C programming basics strong?
Practise more programs on each and every topic of C.
Mohit
0 0
5
How do you print an address?
int main(){ int a=5; printf("Address of variable a is: %d",&a); return 0; }
Prakash
2 0
6
How do you override a defined macro?
We can use the #ifdef and #undef directive to undefine a previously defined macro.
Sharmistha
What does the modulus operator do?
Modulus operator '%' gives the remainder of any expression. For example : r=10%3; // r is 1 , because if you divide 10 by 3 then the remainder is 1
Sumit

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Working with C/C++ applications
Inorder to learn C and C++ programming languages one can work with various editors available.To name a few are the most popular one is turbo c++, DEV C++, Eclipse, NetBeans. Here are the screen shots...

C Program-Error Handling[Program Exit Status]
//Header files #include<stdio.h>#include<conio.h>#include<stdlib.h> //Main Function void main(){ int dividend=20; int divisor=5; int quotient; //Function for clearing screen clrscr();...

C for Begginers
C is an procedure oriented programming language. For any begginer the word program is new. Program: Set of instructions to be followed by machine or computer. Instruction Examples: Arithmetic instruction...

Difference Between C Language and C Program
C Language: C Language is structured, high level and machine independent language. C Program: C Program is the collection of functions that are supported by C library.
S

Shashwat Kumar

0 0
0

Find out the Output of the following with reason and get C Language Training fess less by 10%
1. void main() { clrscr(); printf(5+"Beautifull"); getch(); } 2. void main() { int a=50; clrscr(); ...

Recommended Articles

Lasya Infotech is a Hyderabad based IT training institute founded in 2016 by O Venkat. Believing in his innovation, passion and persistence and with a diverse blend of experience, he started his brainchild to deliver exemplary professional courses to aspiring candidates by honing their skills. Ever since the institute envisions...

Read full article >

Brilliant Academy is one of the reputed institutes for B.Tech tuition classes. This institute is specialised in delivering quality tuition classes for B.E, Engineering - all streams and Engineering diploma courses. Incorporated in 2012, Brillant Academy is a brainchild of Mr Jagadeesh. The main motto of the academy is to...

Read full article >

Almost all of us, inside the pocket, bag or on the table have a mobile phone, out of which 90% of us have a smartphone. The technology is advancing rapidly. When it comes to mobile phones, people today want much more than just making phone calls and playing games on the go. People now want instant access to all their business...

Read full article >

Whether it was the Internet Era of 90s or the Big Data Era of today, Information Technology (IT) has given birth to several lucrative career options for many. Though there will not be a “significant" increase in demand for IT professionals in 2014 as compared to 2013, a “steady” demand for IT professionals is rest assured...

Read full article >

Looking for C Language Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for C Language Classes?

The best tutors for C Language Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn C Language with the Best Tutors

The best Tutors for C Language Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more