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 are portions of a program disabled in demo versions?
By inserting comments in the program Single line comment denoted by // Multi line comment denoted by /* */
Akhilesh
0 0
5
Should variables be stored in local blocks?
Variables in local blocks are auto variables, meaning created and removed from memory, automatically.
Sayed

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

Ask a Question

Related Lessons

Introduction to Programming Languages
What is a Programming Language? A programming language is a formal computer language or constructed language designed to communicate instructions to a machine, particularly a computer. Programming languages...

What Would Be Life Cycle Of A Fresher After Campus In An IT Company?
1. Basic Technical Training: Since freshers are not subject matter experts so gone through 3 - 6 months basic technical training within Organization. 2. Technical Assessment: HR sends freshers to various...

Program to swap the value of two variables without using third variable(simplest way)...
int main() { int a=10,b=20; printf("values of a before swap ="%d,a); printf("values of b before swap ="%d,b); a=a+b; b=a-b; a=a-b; printf("******************"); printf("values of a after swap...

Functions In C Programming
A C-language program is nothing but collection of Function, these are the building blocks of a ‘C’ program. Generally, a function mans a task. “Function is a...

C Programming basics
C PROGRAMMING BASICS 10 Hours Introduction to ‘ C’ programming –fundamentals – structure of a ‘C’...
O

Om K.

0 0
0

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