This directory contains C programs that demonstrate various string and array manipulation functions. The programs cover tasks such as string concatenation, string comparison, string copying, and more.
- File:
0-strcat.c - Prototype:
char *_strcat(char *dest, char *src); - Description: This function appends the
srcstring to thedeststring, overwriting the terminating null byte (\0) at the end ofdest, and then adds a terminating null byte. It returns a pointer to the resulting stringdest.
- File:
1-strncat.c - Prototype:
char *_strncat(char *dest, char *src, int n); - Description: This function is similar to the
_strcatfunction but with the added feature that it will use at mostnbytes fromsrc. Ifsrcdoes not contain a null byte in the firstnbytes, the result will not be null-terminated.
- File:
2-strncpy.c - Prototype:
char *_strncpy(char *dest, char *src, int n); - Description: This function works exactly like the
strncpyfunction from the standard library. It copies at mostncharacters from thesrcstring into thedeststring. Ifsrcis shorter thanncharacters, the remaining characters indestare filled with null bytes (\0).
- File:
3-strcmp.c - Prototype:
int _strcmp(char *s1, char *s2); - Description: This function compares two strings
s1ands2and returns an integer value indicating their relationship. It returns:- 0 if
s1ands2are equal, - a negative value if
s1is less thans2in lexicographical order, and - a positive value if
s1is greater thans2in lexicographical order.
- 0 if
- File:
4-rev_array.c - Prototype:
void reverse_array(int *a, int n); - Description: This function reverses the content of an array of integers. It takes an array
awithnelements, and it modifies the arrayain place, reversing its content.
- File:
5-string_toupper.c - Prototype:
char *string_toupper(char *); - Description: This function changes all lowercase letters of a string to uppercase. It takes a string as input and returns a pointer to the resulting uppercase string.
- File:
6-cap_string.c - Prototype:
char *cap_string(char *); - Description: This function capitalizes all words of a string. Words are separated by spaces, tabs, new lines, commas, semicolons, periods, exclamation marks, question marks, double quotes, opening parentheses, and closing parentheses. It takes a string as input and returns a pointer to the resulting string with capitalized words.
- File:
7-leet.c - Prototype:
char *leet(char *); - Description: This function encodes a string into "1337" (leet speak). The encoding rules are as follows:
- Letters 'a' and 'A' are replaced by '4'.
- Letters 'e' and 'E' are replaced by '3'.
- Letters 'o' and 'O' are replaced by '0'.
- Letters 't' and 'T' are replaced by '7'.
- Letters 'l' and 'L' are replaced by '1'.
- Other characters are unchanged. It takes a string as input and returns a pointer to the resulting leet speak string.
- File:
100-rot13.c - Prototype:
char *rot13(char *); - Description: This function encodes a string using ROT13 encryption. ROT13 is a simple letter substitution cipher where each letter in the input is shifted by 13 positions in the alphabet. It takes a string as input and returns a pointer to the resulting encrypted string.
- File:
101-print_number.c - Prototype:
void print_number(int n); - Description: This function prints an integer
n. It uses only the_putcharfunction to print the number.
- File:
103-infinite_add.c - Prototype:
char *infinite_add(char *n1, char *n2, char *r, int size_r); - Description: This function adds two numbers represented as strings and stores the result in a buffer
r. The size of the buffer is specified bysize_r. The function returns a pointer to the result string. If the result cannot be stored in the buffer due to its size, the function returns0.
- File:
103-print_buffer.c - Prototype:
void print_buffer(char *b, int size); - Description: This function prints the content of a buffer
bof sizesize. It prints 10 bytes per line, showing the position of the first byte of the line in hexadecimal. Each line also shows the hexadecimal content (2 chars) of the buffer, 2 bytes at a time, separated by a space. If the byte is a printable character, it is printed; otherwise, a period (.) is printed. Each line ends with a new line\n. Ifsizeis 0 or less, the output is a new line only\n.
Please note that the _putchar function used in some files is a custom function used to print characters.
Enjoy coding! 🚀