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

  • Thread starter Thread starter aliz_khanz
  • Start date Start date
Click For Summary
SUMMARY

The discussion focuses on creating a function named reverse that inverts the order of characters in a text array using the scanf function in C programming. The function signature is void reverse(char s[]), where s[] is the character array to be reversed. Participants emphasize the importance of understanding loops and suggest using a swap function to facilitate the reversal process. Additionally, they clarify that the last character of the array should be a null terminator to determine the string's length.

PREREQUISITES
  • Understanding of C programming syntax
  • Familiarity with character arrays in C
  • Knowledge of loops and control structures
  • Experience with the scanf function for input handling
NEXT STEPS
  • Implement a character swap function in C
  • Learn about string manipulation techniques in C
  • Explore the use of null terminators in character arrays
  • Practice writing and debugging C programs that utilize loops
USEFUL FOR

Students learning C programming, beginner developers seeking to understand string manipulation, and anyone interested in algorithm development for character arrays.

aliz_khanz
Messages
26
Reaction score
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
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"
 
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?
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 21 ·
Replies
21
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K