-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_call2.c
More file actions
98 lines (98 loc) · 2.33 KB
/
Copy pathfunction_call2.c
File metadata and controls
98 lines (98 loc) · 2.33 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include<stdio.h>
#include<string.h>
void uppr(char str[100],int l);
void lwr(char str[100],int l);
int length(char st[100]);
void main()
{
char ch;
printf("Enter 'L' for lower case and 'U' for uppercase\n");
printf("Enter your choice:\n");
scanf("%c",&ch);
switch(ch)
{
case 'U':
{
char str1[100];
int a=0,size=0;
printf("Enter any text in lower case:\n");
gets(str1);
fgets(str1,sizeof(str1),stdin);
str1[strcspn(str1, "\n")] = '\0';
size=length(str1);
//printf("%d\n",size);
for(a=0;a<=size;a++)
{
if(str1[a]>=65&&str1[a]<=90)
{
printf("Already in upper case letter.");
break;
}
}
uppr(str1,size);
}
break;
case 'L':
{
char str2[100];
int a=0,size2=0;
printf("Enter any text in upper case:\n");
gets(str2);
fgets(str2,sizeof(str2),stdin);
str2[strcspn(str2, "\n")] = '\0';
size2=length(str2);
//printf("%d\n",size);
for(a=0;a<=size2;a++)
{
if(str2[a]>=97&&str2[a]<=122)
{
printf("Already in lower case letter.");
break;
}
}
lwr(str2,size2);
}
break;
default:
{
printf("Wrong choice");
}
}
system("pause");
}
//Writting the function to calculate the length of the string.
int length(char st[100])
{
int i=0;
for(i=0;st[i]!='\0';i++);
return i;
}
//Writting the toupper() function
void uppr(char st[100],int l)
{
int i=0,num=0;
for(i=0;st[i]!='\0';i++)
{
num=(int)st[i]-32;
printf("%c",(char)num);
if(st[i]==' ')
{
printf(" ");
}
}
}
//Writting the tolower() function
void lwr(char st[100],int l)
{
int i=0,num=0;
for(i=0;st[i]!='\0';i++)
{
num=(int)st[i]+32;
printf("%c",(char)num);
if(st[i]==' ')
{
printf("\b ");
continue;
}
}
}