answersLogoWhite

0

{

// get input

char input[256];

gets(input);

// reverse it

char reverse[256];

strReverse(input, reverse);

}

// reverses str and puts the result in buff

// NOTE: buff must be at least as large as str

void strReverse(const char* str, char* buff) {

const int length = strlen(str);

// special case for zero-length strings

if( length == 0 ) {

return;

}

// reversify

int i;

for(i = 0; i < length; ++i) {

buff[i] = str[length - i - 1];

}

buff[i] = '\0';

}

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

Can you provide an example of how to use the keyword "headstring" in a programming function?

In programming, the keyword &quot;headstring&quot; can be used to extract a specific number of characters from the beginning of a string. For example, in a function that takes a string as input and uses &quot;headstring&quot; to extract the first 5 characters, the code might look like this: python def extractheadstring(inputstring): head inputstring:5 return head In this function, the &quot;headstring&quot; keyword is used to extract the first 5 characters from the input string and return them as a new string.


How do I reverse a String and at the same time delete one letter (until all what's left is a single letter) using loops (JAVA)?

I have some knowledge of programming but I'm unsure of anything in java, my explanation is created out of my understanding of JavaScript. I will try to express variables within parenthesis () Reversing The Input (assuming you know how to retrieve user input) My suggestion is to create a variable named (i) and set it to the length of a variable called (string),// the user's input //, and create a loop repeating length of (string) times, where each time through variable (i) changes by - (1), and join letter (i) of (string) to a new variable (reversed_string), and you have the reversed the string. Taking away last letter each time Reposted, if image doesn't show I'll try to explain it. The code is based on JavaScript language


What is a format specifier?

There are many types of format specifier. Exp:%d (To show the integer) %c(To show the character) %f(Float are digits with decimal points to use it to show them) %s(String to show the string)


Anyone knows a programming code to look for nth word in a string using string.h?

Function strtok can help you to separate the words.


Print reverse string in c sharp?

To print a reverse string in C#, you can use the Array.Reverse method or LINQ. Here's a simple example using Array.Reverse: string original = &quot;Hello, World!&quot;; char[] charArray = original.ToCharArray(); Array.Reverse(charArray); string reversed = new string(charArray); Console.WriteLine(reversed); This code converts the string to a character array, reverses the array, and then creates a new string from the reversed array before printing it.


Sample code in java programming?

public class Hello { public static void main (String args[]) { System.out.println("Hello World"); } }


How the pin no is generated in the ATM?

there is a programming code for it which takes 16 digit as input , plays with it in a c programme and gives a 4 digit output...........


Vb net code for to get last 6 digits when gave more than 6 degits?

Dim input As String Dim inputNum As Integer 'Get input input = Console.ReadLine() 'Convert input to number and chop off all but the last 6 digits inputNum = Integer.Parse(input) Mod 1000000 'Display parsed input Console.WriteLine(inputNum)


What is the Programming code for shortest job first?

What is the Programming code for shortest job first?


What are the distinguishing features of the programming language called Short Code?

programming language called Short Code


String to matrix converting matlab code?

Here is an example code snippet in MATLAB that converts a string into a matrix: str = '123456789'; % input string numChars = length(str); % number of characters in the string matrixSize = ceil(sqrt(numChars)); % calculate the size of the resulting matrix % pad the string with zeros to make it divisible by the matrix size str = [str, num2str(zeros(1, matrixSize^2 - numChars))]; % reshape the string into a matrix matrix = reshape(str, matrixSize, matrixSize); This code takes an input string and calculates the size of the matrix needed to store all the characters. It then pads the string with zeros to make it divisible by the matrix size. Finally, it uses the reshape function to convert the string into a matrix.


How do you reverse a string in C?

Code example:/* ******************************************************************************** * FUNCTION: cpReverseStr ******************************************************************************** * DESCRIPTION: * Reverses a given string. Overwrites original. * * PARAMETERS: * cpString: The string to reverse. * * RETURNS: * Reversed string. ******************************************************************************** */ char * cpReverseStr( char *cpString) { register char cTmp; register char *cpFirst = cpString; register char *cpLast = cpFirst + strlen(cpString) - 1; while(cpFirst < cpLast) { cTmp = *cpFirst; *cpFirst = *cpLast; *cpLast = cTmp; cpFirst++; cpLast--; } return cpString; }