0% found this document useful (0 votes)
2 views4 pages

String

The document contains multiple C programs demonstrating various string manipulation functions from the string.h library. These include calculating string length, copying strings, concatenating strings, comparing strings, converting strings to uppercase and lowercase, and reversing a string. Each program showcases a specific functionality with example outputs.

Uploaded by

niveditasss0018
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

String

The document contains multiple C programs demonstrating various string manipulation functions from the string.h library. These include calculating string length, copying strings, concatenating strings, comparing strings, converting strings to uppercase and lowercase, and reversing a string. Each program showcases a specific functionality with example outputs.

Uploaded by

niveditasss0018
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#include <stdio.

h>
#include <string.h>

int main() {
char str[] = "Hello World";
printf("The length of the string is: %zu\n", strlen(str));
return 0;
}

#include <stdio.h>
#include <string.h>

int main() {
char src[] = "Hello World";
char dest[20];
strcpy(dest, src);
printf("The copied string is: %s\n", dest);
return 0;
}

#include <stdio.h>
#include <string.h>

int main() {
char str1[] = "Hello";
char str2[] = "World";
strcat(str1, str2);
printf("The concatenated string is: %s\n", str1);
return 0;
}

#include <stdio.h>
#include <string.h>

int main() {
char str1[] = "Hello";
char str2[] = "World";
int result = strcmp(str1, str2);
if(result == 0) {
printf("The strings are equal.\n");
}
else if(result < 0) {
printf("The first string is less than the second string.\n");
}
else {
printf("The first string is greater than the second string.\n");
}
return 0;
}

#include <stdio.h>
#include <string.h>
int main() {
char str[] = "Hello, World!";
printf("Original string: %s\n", str);
// Convert string to uppercase
strupr(str);
printf("Uppercase string: %s\n", str);
return 0;
}

#include <stdio.h>
#include <string.h>

int main() {
char str[] = "Hello, World!";
printf("Original string: %s\n", str);
// Convert string to lowercase
strlwr(str);
printf("Lowercase string: %s\n", str);

return 0;
}

#include <stdio.h>
#include <string.h>
int main()
{
char str[40]; // declare the size of character string
printf(" \n Enter a string to be reversed: ");
scanf("%s", str);

// use strrev() function to reverse a string


printf(" \n After the reverse of a string: %s ", strrev(str));
return 0;
}

You might also like