Exercises String
Exercises String
Exercises String
1. Length of a String:
Explanation: ???
2. String Copy:
Write a function char *strcpy(char *dest, char *src) that copies the contents
of one string to another.
Explanation: ???
3. String Concatenation:
Write a function char *strcat(char *dest, char *src) that appends one string
to the end of another.
Explanation: ???
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.
Explanation: ???
5. Reverse a String:
Explanation: ???
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.
Explanation: ???
8. Find a Substring:
Write a function char *findSubstring(char *str, char *substr) that finds the
first occurrence of a substring within a string.
Explanation: ???
9. Remove a Substring:
Explanation: ???
Explanation: ???
Explanation: ???
Write functions char *ltrim(char *str) and char *rtrim(char *str) that remove
leading and trailing whitespace from a string, respectively.
Explanation: ???
13. Split a String:
Write a function char **split(char *str, char delimiter) that splits a string into
an array of strings based on a delimiter character.
Explanation: ???
Example:
#include <stdio.h>
#include <string.h>
int main() {
char destination[20];
return 0;
Output:
strncpy(): Hello
#include <stdio.h>
#include <string.h>
int main() {
return 0;
Output:
Example:
#include <stdio.h>
#include <string.h>
int main() {
Output:
strncmp(): 7
Example:
#include <stdio.h>
#include <string.h>
int main() {
return 0;
Output:
Example:
#include <stdio.h>
#include <string.h>
int main() {
char sentence[] = "This is a sample sentence.";
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() {
return 0;
}
Output: