-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCyclicShifting.c
More file actions
42 lines (35 loc) · 813 Bytes
/
CyclicShifting.c
File metadata and controls
42 lines (35 loc) · 813 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
41
42
#include <stdio.h>
#include <stdlib.h>
int main()
{
int s = 1;
char str[255];
printf("Input a sentence: ");
fgets(str, 255, stdin);
//Counting the number of words
for(int j = 0; j < strlen(str); j++){
if(str[j] == ' '){
s++;
}
}
char words[s][255];
int v = 0, z = 0;
//Splitting the sentence into words
for(int k = 0; k < strlen(str); k++){
if(str[k] == ' ' || str[k] == '\n'){
words[v][z] = '\0';
z = 0;
v++;
}
else{
words[v][z] = str[k];
z++;
}
}
//Printing the words with one postion shifted
printf("%s ", words[s-1]);
for(int j = 0; j < s-1; j++){
printf("%s ", words[j]);
}
return 0;
}