
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
C Program to Reverse Array of Strings
In this problem, we are given an array of string. Our task is to create a c program to reverse array of strings.
We will reverse the array elements i.e. last element to the first value and so on.
Let’s take an example to understand the problem,
Input
strarr[] = {"learn", "programming", "at", "tutorialspoint"}
Output
strarr[] = {"tutorialspoint", "at", "programming", "learn"}
To solve this problem, we will create an array of pointers and use two pointers from start and end. then move the pointers towards the opposite side, and keep on swapping the pointer values.
C program to reverse array of strings.
//c program to reverse array of strings.
Example
#include <stdio.h> #include <string.h> void ReverseStringArray(char* strarr[], int n) { char* temp; int end = n - 1; for (int start = 0; start < end; start++) { temp = strarr[start]; strarr[start] = strarr[end]; strarr[end] = temp; end--; } } int main() { char* strarr[] = {"learn", "programming", "at", "tutorialspoint"}; int n = sizeof(strarr) / sizeof(strarr[0]); for (int i = 0; i < n; i++) printf("%s ", strarr[i]); printf("
"); ReverseStringArray(strarr, n); for (int i = 0; i < n; i++) printf("%s ", strarr[i]); return 0; }
Output
learn programming at tutorialspoint tutorialspoint at programming learn
- Related Articles
- C++ program to concatenate strings in reverse order
- C# program to reverse an array
- Write a C program to reverse array
- C program to reverse an array elements
- Python program to count the pairs of reverse strings
- C++ program to reverse an array elements (in place)
- C Program to Sort an array of names or strings
- Java program to reverse an array
- C program to print array of pointers to strings and their address
- C++ Array of Strings
- Python program to reverse a Numpy array?
- Write a program to reverse an array or string in C++
- C# Program to search for a string in an array of strings
- Program to reverse a sentence words stored as character array in C++
- Write a Golang program to reverse an array

Advertisements