Exercises String
Exercises String
Exercises String
Length of a String:
2. String Copy:
Write a function char *strcpy(char *dest, char *src) that copies the contents
of one string to another.
3. String Concatenation:
Write a function char *strcat(char *dest, char *src) that appends one string
to the end of another.
4. String Comparison:
Write a function int strcmp(char *str1, char *str2) that compares two strings
lexicographically and returns 0 if they are equal, a negative value if
str1 is less than str2, and a positive value if str1 is greater than str2.
5. Reverse a String:
6. Palindrome Check:
7. Character Count:
Write a function int countChar(char *str, char c) that counts the number of
occurrences of a specific character in a string.
8. Find a Substring:
Write a function char *findSubstring(char *str, char *substr) that finds the first
occurrence of a substring within a string.
9. Remove a Substring:
Write a function void removeSubstring(char *str, char *substr) that removes all
occurrences of a substring from a string.
Write functions char *ltrim(char *str) and char *rtrim(char *str) that remove
leading and trailing whitespace from a string, respectively.
Write a function char **split(char *str, char delimiter) that splits a string into
an array of strings based on a delimiter character.
Example:
#include <stdio.h>
#include <string.h>
int main() {
char destination[20];
return 0;
Output:
strncpy(): Hello
Example:
#include <stdio.h>
#include <string.h>
int main() {
return 0;
Output:
Example:
#include <stdio.h>
#include <string.h>
int main() {
return 0;
Output:
strncmp(): 7
Example:
#include <stdio.h>
#include <string.h>
int main() {
return 0;
Output:
Example:
#include <stdio.h>
#include <string.h>
int main() {
return 0;
Output:
Example:
#include <stdio.h>
#include <string.h>
int main() {
char text[] = "The quick brown fox jumps over the lazy dog.";
return 0;
}
Output:
Example:
#include <stdio.h>
#include <string.h>
int main() {
return 0;
Output:
strtok(): This
strtok(): is
strtok(): a
strtok(): sample
strtok(): sentence
Example:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main() {
toLowerCase(str5);
return 0;
Output:
strlwr(): lowercase
Example:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main() {
toUpperCase(str6);
return 0;
Output:
strupr(): UPPERCASE
Example:
#include <stdio.h>
#include <string.h>
int main() {
Output: