You are on page 1of 4

include <stdio.

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!

1. strcat( ):- String Concatenation


This function is used to concatenates (joins) two string into ‘single’ string.
Syntax: strcat(str1,str2);
Where str2 is concatenated at the end of the str1.
Example: char str1[10] =”Hello”;
int=strlen(str1): //n value is 5
2. strcmp( ):- String Compare
The string compare function is used to compares twe string, character by character.
It accepts strings as parameters and returns integer value. If string is matched, retures 0 otherwise
retures some integer value

Syntax: int n=strcmp(str1,str2);

Example: chat str1[10]=”Hello”; char str2[10]=”Hello”;


int n=strcmp(str1,str2); //return 0 both the string are equal.
3. strrev():- String Reverse
This function is used to reverse the given string.
Syntax: strrev(str1);
Example: char str1[10]=”C Program”;
Strrev(str1); //str1 has magorP C
4. strcpy( ):- String Copy
The strcpy() copies the contents of one string to another. It takes two arguments, first
argument is the destination and second as source string array. The source string is copied into
destination string.
Syntax: strcpy(destination_string, Source_string);
Example: char str1[10]=”Hello”; char str2[10]; strcpy(str2,str1); //str2 has Hello String;

#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

You might also like