Question

Using C,

Write a function reverse which takes a string as an argument, reverses the string and returns the reversed string. Note; you

0 0
Add a comment Improve this question Transcribed image text
Answer #1
code in bold is the function you neea .

#include <stdio.h>

char *reverse(char *string) {
    int i, len = 0;
    char temp;
    while (string[len]) {
        len++;
    }
    for (i = 0; i < len/2; ++i) {
        temp = string[i];
        string[i] = string[len-i-1];
        string[len-i-1] = temp;
    }
    return string;
}

int main() {
    char str[] = "hello";
    printf("%s", reverse(str));
    return 0;
}

olleh Process finished with exit code 0

Add a comment
Know the answer?
Add Answer to:
Using C, Write a function reverse which takes a string as an argument, reverses the string...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C function first_last that consumes a string argument and modifies it so that it...

    Write a C function first_last that consumes a string argument and modifies it so that it only contains two characters the first, and the last. If there are less than two characters, leave the string alone. Return nothing For example: Test Result char str[]="hello"; first_last(str) printf("%s", str); ho

  • RUBY! \Write a method called reverse_each_word that takes in a string argument of a sentence and...

    RUBY! \Write a method called reverse_each_word that takes in a string argument of a sentence and returns that same sentence with each word reversed in place. First solve it using .each Then utilize the same method using .collect to see the difference. For example: reverse_each_word("Hello there, and how are you?") #=> "olleH ,ereht dna woh era ?uoy" Hint: You can't use an enumerator on a string, so how can we turn our string into an array? Hint: How can we...

  • Write a function that takes a string as a parameter and returns a new string that...

    Write a function that takes a string as a parameter and returns a new string that is the reverse of the old string. Python from test import testEqual def reverse(s): return s testEqual(reverse("hello"),"olleh") testEqual(reverse("l"),"l") testEqual(reverse("follow"),"wollof") testEqual(reverse(""),"")

  • Write a function called smallestLetter that takes in a string argument and returns a char. The...

    Write a function called smallestLetter that takes in a string argument and returns a char. The char that is returned by this function is the character in the string with the lowest ASCII integer code. For example: smallestLetter("Hello") returns ‘H’ which is code 72, and smallestLetter("Hello World") returns ‘ ’ (The space character) which is code 32

  • Write a function in HASKELL to reverse a string (or list) without using the built-in reverse...

    Write a function in HASKELL to reverse a string (or list) without using the built-in reverse function.           Example:           Hello as olleh or [1,3,4,5] as [5,4,3,1].

  • Write a function in c++: Write a function, reverseString(string &str), that reverses the characters of the...

    Write a function in c++: Write a function, reverseString(string &str), that reverses the characters of the string str, except ignore sections of numbers starting with a 6 and extending to the next 7 (every 6 will be followed by at least one 7). Return 0 for no numbers. string example = "Reverse"; reverseString(example), cout << example; // prints out "esreveR"

  • C++ Write a recursive function that reverses the given input string. No loops allowed, only use...

    C++ Write a recursive function that reverses the given input string. No loops allowed, only use recursive functions. Do not add more or change the parameters to the original function. Do not change the main program. #include <iostream> #include <string> using namespace std; //Write a recursive function 'void reverse(string &str)' that reverses the given input string. void reverse(string &str) { /*Code needed*/ } int main() {    string name = "sherry";    reverse(name);    cout << name << endl; //should...

  • Using Python: #Write a letterAppearance function that takes a string, str as argument #letterAppearance will count...

    Using Python: #Write a letterAppearance function that takes a string, str as argument #letterAppearance will count the number of times each letter appears in a string #using a dictionary. #letterAppearance returns only the letters that appear in the string. #Capitalization should not matter ''' letterAppearance('hello') #{'h': 1, 'e': 1, 'l': 2, 'o': 1} letterAppearance('Hello') #{'h': 1, 'e': 1, 'l': 2, 'o': 1} letterAppearance('mutation') #{'m': 1, 'u': 1, 't': 2, 'a': 1, 'i': 1, 'o': 1, 'n': 1} '''

  • Write a program in MIPS to accept a string from a user, reverse that string and...

    Write a program in MIPS to accept a string from a user, reverse that string and print it out to the user. You must write a procedure that performs the reversal task. Example: Please Enter a String: Hello How Are You Reversed String: uoY erA woH olleH

  • Programs 1. String Utilities In this exercise you will implement several utility functions involving strings. You...

    Programs 1. String Utilities In this exercise you will implement several utility functions involving strings. You will place all of your function prototypes in a header file named string utils.h and all of your function definitions in a source file named string utils.c. You should implement your own main test driver program to test your functions, but you need not hand it in. a. void addChar(char *str, char c, int n) - this function should add a char c at...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT