-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassign7-4.c
More file actions
40 lines (40 loc) · 756 Bytes
/
assign7-4.c
File metadata and controls
40 lines (40 loc) · 756 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
36
37
38
39
40
//Reverse every Word of Given String
#include<stdio.h>
#include<stdlib.h>
void reverse(char *start,char *end)
{
while(start<end)
{
char temp=*start;
*start=*end;
*end=temp;
start++;
end--;
}
}
void reverse_str(char str[])
{
char *word_start=NULL;
char *temp=str;
while (*temp)
{
if((word_start==NULL)&&(*temp!=' '))
{
word_start=temp;
}
if (word_start&&(*(temp+1)==' '||*(temp+1)=='\0'))
{
reverse(word_start,temp);
word_start=NULL;
}
temp++;
}
}
int main()
{
char s1[100];
fgets(s1,100,stdin);
reverse_str(s1);
printf("Output=%s",s1);
return 0;
}