Professional Documents
Culture Documents
h>
#include <ctype.h>
int main()
{
char input[100];
int vowels = 0, consonants = 0, spaces = 0, symbols = 0;
printf("Enter a string: ");
scanf(“%s”, &input);
for (int i = 0; input[i] != '\0'; i++)
{
char ch = tolower(input[i]);
if (isalpha(ch))
{
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
{
vowels++;
}
else
{
consonants++;
} else if (isspace(ch)) {
spaces++;
} else {
symbols++;
}
}
printf("Vowels: %d\nConsonants: %d\nSpaces: %d\nSpecial Symbols: %d\n", vowels, consonants,
spaces,
symbols);
return 0;
}
OUTPUT:
Enter a string: Hello World! 123
Vowels: 3
Consonants: 7
Spaces: 2
Symbols: 3
#include <stdio.h>
#include <string.h>
int main() {
// Example strings
char str1[100] = "Hello";
char str2[100] = " World!";
char str3[100];
// Using strlen
int length = strlen(str1);
printf("Length of str1: %d\n", length);
// Using strcpy
strcpy(str3, str1);
printf("After strcpy, str3 is: %s\n", str3);
// Using strcat
strcat(str3, str2);
printf("After strcat, str3 is: %s\n", str3);
// Using strlen
int length = strlen(str1);
printf("Length of str1: %d\n", length);
// Using strcpy
strcpy(str3, str1);
printf("After strcpy, str3 is: %s\n", str3);
// Using strcat
strcat(str3, str2);
printf("After strcat, str3 is: %s\n", str3);
// Using strcmp
int result = strcmp(str1, str2);
if (result == 0)
{
printf("str1 and str2 are equal.\n");
}
else if (result < 0)
{
printf("str1 is less than str2.\n");
}
else
{
printf("str1 is greater than str2.\n");
}
// Using strlwr
strlwr(str3);
printf("After strlwr, str3 is: %s\n", str3);
// Using strupr
strupr(str3);
printf("After strupr, str3 is: %s\n", str3);
return 0;
}
OUTPUT:
Length of str1: 5
After strcpy, str3 is: Hello
After strcat, str3 is: Hello World!
str1 is less than str2.
After strlwr, str3 is: hello world!
After strupr, str3 is: HELLO WORLD!
#include <stdio.h>
#include <string.h>
int main() {
char str1[100] = "Unique";
char str2[100] = " String!";
char str3[100];
// Using strlen
int length = strlen(str1);
printf("Length of str1: %d\n", length);
// Using strcpy
strcpy(str3, str1);
printf("After strcpy, str3 is: %s\n", str3);
// Using strcat
strcat(str3, str2);
printf("After strcat, str3 is: %s\n", str3);
// Using strcmp
int result = strcmp(str1, str2);
if (result == 0) {
printf("str1 and str2 are equal.\n");
} else if (result < 0) {
printf("str1 is less than str2.\n");
} else {
printf("str1 is greater than str2.\n");
}
return 0;
}
OUTPUT:
Length of str1: 6
After strcpy, str3 is: Unique
After strcat, str3 is: Unique String!
str1 is greater than str2.
Function Description
strlen() It returns the string's length.
strcmp() It compares two strings and returns 0 if the strings are thesame.
strcat() It concatenates two strings and returns the concatenatedstring.
strcpy() It copies one string into another.
strlwr() Lower case
strupr() Uppercase
#include <stdio.h>
#include <string.h>
int main() {
// Example string
char str[100];
// Input a string
printf("Enter a string: ");
scanf(“%s”, str);
// Calculate the length of the string using strlen
int length = strlen(str);
// Reverse the string using for loop
for (int i = length - 1; i >= 0; i--) {
printf(“%c”, (str[i]);
}
return 0;
}
OUTPUT:
!dlroW olleH