-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrev.c
More file actions
22 lines (22 loc) · 735 Bytes
/
rev.c
File metadata and controls
22 lines (22 loc) · 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
reverse ()
{
char str[50], temp; // define the size of str[] array
int i, left, right, len;
printf (" \n Display a reverse string in the C: \n");
printf (" ----------------------- ");
printf (" \n Enter a string to reverse order: ");
scanf( "%s", &str);
len = strlen(str); // get the length of the string
left = 0; // set left index at 0
right = len - 1; // set right index len - 1
// use for loop to store the reverse string
for (i = left; i <right; i++)
{
temp = str[i];
str[i] = str[right];
str[right] = temp;
right--;
}
printf (" The reverse of the original string is: %s ", str);
// getch();
}