-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path19. Understand the use of various string operations.c
56 lines (44 loc) · 1.33 KB
/
19. Understand the use of various string operations.c
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
#include <stdio.h>
#include <string.h>
#include <ctype.h>
// Program to demostrate the use of string operations
int main(){
char str1[50];
char str2[50];
printf("Enter the first string: ");
scanf("%49s", str1);
printf("Enter the second string: ");
scanf("%49s", str2);
char concatStr[100];
char copyStr[50];
char reversedStr[50];
char substring[20];
char upperStr[50];
char lowerStr[50];
printf("\n1. Length of \"%s\": %lu\n", str1, strlen(str1));
strcpy(concatStr, str1);
strcpy(concatStr, " ");
strcpy(concatStr, str2);
printf("2.Concatenated Strings: %s\n", concatStr);
strcpy(copyStr, str1);
printf("3. Copied String: %s\n", copyStr);
if(strcmp(str1, str2) == 0)
printf("4. Entered Strings are Equal.\n");
else
printf("4. Entered Strings are not Equal.\n");
strcpy(reversedStr, str1);
// strrev(reversedStr);
printf("5. Reversed \"%s\": \"%s\"\n", str1, reversedStr);
strncpy(substring, str1 +1, 3);
substring[3] = '\0';
printf("6. Substring of \"%s\": \"%s\"\n", str1, substring);
strcpy(upperStr, str1);
for (int i=0; i<strlen(str1); i++)
upperStr[i] = toupper(upperStr[i]);
printf("7. UpperCase of \"%s\": \"%s\"\n", str1, upperStr);
strcpy(lowerStr, str1);
for (int i=0; i<strlen(str1); i++)
lowerStr[i] = tolower(lowerStr[i]);
printf("8. LowerCase of \"%s\": \"%s\"\n", str1, lowerStr);
return 0;
}