-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path44.c
More file actions
35 lines (35 loc) · 701 Bytes
/
44.c
File metadata and controls
35 lines (35 loc) · 701 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdio.h>
int main()
{
char str[100];
int length = 0, i;
char temp;
// Input string
printf("Enter a string: ");
fgets(str, sizeof(str), stdin);
// Remove newline character if fgets used
if (str[0] != '\0')
{
int j = 0;
while (str[j] != '\0' && str[j] != '\n')
{
j++;
}
str[j] = '\0';
}
// Find length manually
while (str[length] != '\0')
{
length++;
}
// Reverse the string by swapping
for (i = 0; i < length / 2; i++)
{
temp = str[i];
str[i] = str[length - i - 1];
str[length - i - 1] = temp;
}
// Print reversed string
printf("Reversed string: %s\n", str);
return 0;
}