-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReverse_Words_Program.c
More file actions
47 lines (31 loc) · 1.04 KB
/
Copy pathReverse_Words_Program.c
File metadata and controls
47 lines (31 loc) · 1.04 KB
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
43
44
45
46
47
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void)
{
//we set our some definition as below
int i;
char (*myWords)[20];
int wordLength=20;
myWords = malloc(wordLength * sizeof *myWords); //we created a dynamic array which will hold our word values
if(myWords==NULL) /*Memory could not be allocated,
the program should handle the error here as appropriate*/
{
printf("Memory error!");
}
else{
for(i=0;i<5;i++)
{
printf("Enter word #%d: ",i+1); //we can enter our value of string (char)
gets(myWords[i]); //we can write any word
strrev(myWords[i]); //after we wrote, here, our word will reverse
}
for(i=0;i<5;i++)
{
printf("%s\n",myWords[i]); //we opened a loop for print our reversing words
}
}
free(myWords); //when we finished our work, then the pointer does free
myWords = NULL; //The pointed-to-data must not used again, unless re-assigned by using malloc again
return 0;
}