answersLogoWhite

0


Best Answer

#include

using std::cin;
using std::cout;
using std::endl;

int main()
{
const int arraySize = 128;
char myString[arraySize] = {'0'};
cout << endl << "Enter a string: " << endl;
cin.getline(myString, 128, '\n');

int numberOfChars = 0;
while ((numberOfChars < (arraySize - 1)) && (myString[numberOfChars] != NULL))
{
++numberOfChars;

}
cout << endl << "You've entered:"
<< endl << myString << endl;


char myStringReversed[arraySize] = {'0'};
int index = 0;
while ((index <= numberOfChars) && (myString[index] != NULL))
{
myStringReversed[numberOfChars - index - 1] = myString[index];
++index;

}
cout << endl << "Reversed string is: "
<< endl << myStringReversed << endl;


system("PAUSE");
return 0;

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Accept a string and reverse a string in c?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the use of Reverse String in C program?

The use of the reverse string in C program is used to reverse the letters in the string. An example would be reverse me would be reversed to em esrever.


How do you convert a number that consist of alphabet and number in reverse order?

To reverse a number, first convert the number to a string, then reverse the string. Given your number consists of alphanumeric characters, the number must already be a string so simply reverse the string: #include&lt;string&gt; using std::string; string reverse (const string&amp; s) { string str {}; for (auto c : s) str.insert (str.begin(), c); return str; } int main () { std::cout &lt;&lt; "Enter a number: "; string s {}; std::cin &gt;&gt; s; std::cout &lt;&lt; "The number in reverse is: " &lt;&lt; reverse (s); }


Write a flowchart of reverse the string in c?

wefwfe


How do you get value of a string in reverse order in c?

Assume C#, not C: Traditional way: public string Reverse(string s) { if (string.IsNullOrEmpty(s)) return s; // "" or null char[] characters = s.ToCharArray(); Array.Reverse(characters); return new string(characters); } or as an extension method: public static string Reverse(this string s) { if (s == "") return ""; char[] characters = s.ToCharArray(); Array.Reverse(characters); return new string(characters); } The differences of the 2 methods above is on the caller (how to use Reverse()), and they may co-exist: For example: string test = "abc"; string result1 = Reverse(test); // traditional way string result2 = test.Reverse(); // call the extension


How to Program for reversal of string ven123kat in c?

#include #include #include int reverse(int i);char st[]="ven123kat";void main() {printf("\nThe string is: %s", st);reverse(0);printf("\nReversed string is: %s", st);getch();}int reverse(int i) {if (i


How do you create a string and reverse a string in vb?

gov


How do you reverse a string in PHP?

A predefined function can reverse a string as shown below:echo strrev('pizza'); // outputs: azzip


Write a C program to accept a string from user and display its ascii value and then display sum of all ascii value of strings?

//C program to accept a string from user and //display its ascii value and //then display sum of all ascii value of strings #include&lt;stdio.h&gt; #include &lt;string.h&gt; int main() { char String[100]; int Sum,Index; Sum=0; //Sum is initially zero printf("Enter the string:\n"); gets(String); //Accept String from User for(Index=0;Index&lt;strlen(String);Index++) { Sum+=(String[Index]); //Adds (the ASCII values of) the String characters. } printf("The sum is %d\n",Sum); //Printing it as %d gives the equivalent ASCII value. return 0; }


How do you write string in reverse through the HTML tags?

Not possible through html. Use php strrev function. For eg:


Reverse of a string without using string handling function?

shashi


Flow chart to reverse digits of numbers?

ALGORITHM REVERSEINPUT (string)"STRINGLENGTH() would be a function that returns the lenght of the string"FOR (i = STRINGLENGTH(string); i >= 0; i--) BEGINDISPAY (string[i])END FOREND REVERSE


Write a program to implement the various operations on string such as length of string concatenation reverse of a string copy of a string to another in VB?

what is string