Skip to content

Commit 977c8a8

Browse files
authored
Add files via upload
1 parent 327b2d2 commit 977c8a8

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

C Assignment 1.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include <stdio.h>
2+
3+
// program to count the words that the user inputs
4+
// also to encrypt the words
5+
6+
int wordCount(char *str)
7+
{
8+
int i = 0;
9+
int count = 1;
10+
while (str[i] != '\0')
11+
{
12+
if (str[i] == ' ' || str[i] == '\n' || str[i] == '\t')
13+
{
14+
count++;
15+
}
16+
i++;
17+
}
18+
return count;
19+
}
20+
21+
void encryption(char *str)
22+
{
23+
char ch;
24+
int i;
25+
int incre = 1;
26+
27+
for(i = 0; str[i] != '\0'; ++i)
28+
{
29+
ch = str[i];
30+
if(ch >= 'a' && ch <= 'z')
31+
{
32+
ch = ch + incre;
33+
34+
if(ch > 'z')
35+
{
36+
ch = ch - 'z' + 'a' - 1;
37+
}
38+
39+
str[i] = ch;
40+
}
41+
}
42+
}
43+
44+
int main()
45+
{
46+
47+
48+
char str[50];
49+
50+
do
51+
{
52+
printf("Enter words: ");
53+
fgets(str, 50, stdin);
54+
}
55+
while (str[1] == '\0');
56+
57+
58+
int wrdCount = wordCount(str);
59+
60+
printf("Number of words: %d\n", wrdCount-1);
61+
62+
encryption(str);
63+
printf("Encrypted text: %s", str);
64+
65+
return 0;
66+
}
67+

0 commit comments

Comments
 (0)