How to Reverse Characters in a Text Array Using the Scanf Function

  • Thread starter aliz_khanz
  • Start date
In summary, the task is to write a function called "reverse" which will invert the order of characters in a given text array. This function will then be applied in a program that reverses the characters in all input lines. The program should prompt the user to enter a string, then reverse the characters of the string and output the result. The solution may involve using a swap function and loops, and should not require the use of the scanf function.
  • #1
aliz_khanz
26
0

Homework Statement



Write a function reverse which inverts the order of character in the text array.
void reverse(char s[])
// s[] – the array containing the character which order has to be inverted
Apply this funtion in a program which inverts the characters in all input lines.

Homework Equations



Scanf maybe ...%"anything"

The Attempt at a Solution



I don't really know where to start as I am unable to understand the question. Can anyone please write this programme for me? I just know that scanf function will be used in order to write the programme.
 
Physics news on Phys.org
  • #2
aliz_khanz said:

Homework Statement



Write a function reverse which inverts the order of character in the text array.
void reverse(char s[])
// s[] – the array containing the character which order has to be inverted
Apply this funtion in a program which inverts the characters in all input lines.

Homework Equations



Scanf maybe ...%"anything"

The Attempt at a Solution



I don't really know where to start as I am unable to understand the question. Can anyone please write this programme for me? I just know that scanf function will be used in order to write the programme.
No, we aren't going to write this program for you. That's not what we do here. We're happy to help you, but you need to make some effort at solving this problem before we can help.

If the user enters the string, "Hi, how are you?" the program should reverse the characters to produce this string "?uoy era woh ,iH"
 
  • #3
Hints,

The last character in the array should be a null, use that to get the length. Try looking up a swap function. Are you familiar with loops? Also I don't see a use for scanf?
 

FAQ: How to Reverse Characters in a Text Array Using the Scanf Function

What is a simple program?

A simple program is a set of instructions written in a programming language that tells a computer what tasks to perform in a specific order. It is the basic building block of any software or application.

How do I write a simple program?

To write a simple program, you must first choose a programming language and then use a code editor to type in your instructions. You can follow tutorials or refer to documentation to learn the syntax and structure of the language.

What are the benefits of writing a simple program?

There are several benefits to writing a simple program, including improved problem-solving skills, better understanding of how computers work, and the ability to automate repetitive tasks. It can also open up opportunities for a career in software development.

Can I write a simple program without any prior coding experience?

Yes, you can write a simple program without any prior coding experience. Many programming languages have a user-friendly syntax and there are plenty of online resources and tutorials available for beginners. It may take some time and practice to become proficient, but anyone can learn to write a simple program.

What are some examples of simple programs?

Some examples of simple programs include a calculator, a to-do list, a countdown timer, and a basic game. These programs typically involve basic operations such as input and output, conditionals, and loops. They are a good starting point for learning how to write more complex programs.

Similar threads

Replies
1
Views
2K
Replies
4
Views
2K
Replies
9
Views
4K
Replies
11
Views
2K
Replies
1
Views
2K
Replies
3
Views
2K
Back
Top