GithubHelp home page GithubHelp logo

21-string's Introduction

21-string


Implementation of some functions of string.h library with tests. The goal of this project is to understand how string processing functions work using C language. In the course of the work, analyze the existing auxiliary functions of string processing, determine how other data types are translated into strings.

USEFUL NOTES:

  • there is a significant difference in work of code on other operating systems. It was not possible to find best testing option, except for using machines on campus. be more careful with the sprintf function. especially with precision, the # flag and wide characters
[ SPOILER ] Overview of implemented code

string.h Types

No. Variable Description Status
1 size_t This is the unsigned integral type and is the result of the sizeof keyword. βœ…

string.h Macro

No. Macro Description Status
1 NULL This macro is the value of a null pointer constant. βœ…

string.h Functions

No. Function Description Status
1 void *memchr(const void *str, int c, size_t n) Searches for the first occurrence of the character c (an unsigned char) in the first n bytes of the string pointed to, by the argument str. β˜‘οΈ
2 int memcmp(const void *str1, const void *str2, size_t n) Compares the first n bytes of str1 and str2. β˜‘οΈ
3 void *memcpy(void *dest, const void *src, size_t n) Copies n characters from src to dest. β˜‘οΈ
4 void *memmove(void *dest, const void *src, size_t n) Another function to copy n characters from src to dest. β˜‘οΈ
5 void *memset(void *str, int c, size_t n) Copies the character c (an unsigned char) to the first n characters of the string pointed to, by the argument str. β˜‘οΈ
6 char *strcat(char *dest, const char *src) Appends the string pointed to, by src to the end of the string pointed to by dest. βœ…
7 char *strncat(char *dest, const char *src, size_t n) Appends the string pointed to, by src to the end of the string pointed to, by dest up to n characters long. βœ…
8 char *strchr(const char *str, int c) Searches for the first occurrence of the character c (an unsigned char) in the string pointed to, by the argument str. βœ…
9 int strcmp(const char *str1, const char *str2) Compares the string pointed to, by str1 to the string pointed to by str2. βœ…
10 int strncmp(const char *str1, const char *str2, size_t n) Compares at most the first n bytes of str1 and str2. βœ…
11 char *strcpy(char *dest, const char *src) Copies the string pointed to, by src to dest. βœ…
12 char *strncpy(char *dest, const char *src, size_t n) Copies up to n characters from the string pointed to, by src to dest. βœ…
13 size_t strcspn(const char *str1, const char *str2) Calculates the length of the initial segment of str1 which consists entirely of characters not in str2. βœ…
14 char *strerror(int errnum) Searches an internal array for the error number errnum and returns a pointer to an error message string. You need to declare macros containing arrays of error messages for mac and linux operating systems. Error descriptions are available in the original library. Checking the current OS is carried out using directives.
15 size_t strlen(const char *str) Computes the length of the string str up to but not including the terminating null character. βœ…
16 char *strpbrk(const char *str1, const char *str2) Finds the first character in the string str1 that matches any character specified in str2. βœ…
17 char *strrchr(const char *str, int c) Searches for the last occurrence of the character c (an unsigned char) in the string pointed to by the argument str. βœ…
18 size_t strspn(const char *str1, const char *str2) Calculates the length of the initial segment of str1 which consists entirely of characters in str2. βœ…
19 char *strstr(const char *haystack, const char *needle) Finds the first occurrence of the entire string needle (not including the terminating null character) which appears in the string haystack. βœ…
20 char *strtok(char *str, const char *delim) Breaks string str into a series of tokens separated by delim. βœ…

sprintf & sscanf

No. Function Description Status
1 int sscanf(const char *str, const char *format, ...) reads formatted input from a string. β˜‘οΈ
2 int sprintf(char *str, const char *format, ...) sends formatted output to a string pointed to, by str. βœ…

sprintf & sscanf Specifiers

No. Specifier sprintf output sscanf output sprintf Status sscanf Status
1 c Character Character βœ… β˜‘οΈ
2 d Signed decimal integer Signed decimal integer βœ… β˜‘οΈ
3 i Signed decimal integer Signed integer (may be decimal, octal or hexadecimal) βœ… β˜‘οΈ
4 e Scientific notation (mantissa/exponent) using e character (the output of the numbers must match up to e-6) Decimal floating point or scientific notation (mantissa/exponent) βœ… β˜‘οΈ
5 E Scientific notation (mantissa/exponent) using E character Decimal floating point or scientific notation (mantissa/exponent) βœ… β˜‘οΈ
6 f Decimal floating point Decimal floating point or scientific notation (mantissa/exponent) βœ… β˜‘οΈ
7 g Uses the shortest representation of decimal floating point Decimal floating point or scientific notation (mantissa/exponent) βœ… β˜‘οΈ
8 G Uses the shortest representation of decimal floating point Decimal floating point or scientific notation (mantissa/exponent) βœ… β˜‘οΈ
9 o Unsigned octal Unsigned octal βœ… β˜‘οΈ
10 s String of characters String of characters βœ… β˜‘οΈ
11 u Unsigned decimal integer Unsigned decimal integer βœ… β˜‘οΈ
12 x Unsigned hexadecimal integer Unsigned hexadecimal integer (any letters) βœ… β˜‘οΈ
13 X Unsigned hexadecimal integer (capital letters) Unsigned hexadecimal integer (any letters) βœ… β˜‘οΈ
14 p Pointer address Pointer address βœ… β˜‘οΈ
15 n Number of characters printed until %n occurs Number of characters scanned until %n occurs βœ… β˜‘οΈ
16 % Character % Character % βœ… β˜‘οΈ

sprintf Flags

No. Flags Description Status
1 - Left-justify within the given field width; Right justification is the default (see width sub-specifier). βœ…
2 + Forces to precede the result with a plus or minus sign (+ or -) even for positive numbers. By default, only negative numbers are preceded with a -ve sign. βœ…
3 (space) If no sign is going to be written, a blank space is inserted before the value. βœ…
4 # Used with o, x or X specifiers the value is preceded with 0, 0x or 0X respectively for values different than zero. Used with e, E and f, it forces the written output to contain a decimal point even if no digits would follow. By default, if no digits follow, no decimal point is written. Used with g or G the result is the same as with e or E but trailing zeros are not removed. βœ…
5 0 Left-pads the number with zeroes (0) instead of spaces, where padding is specified (see width sub-specifier). βœ…

sprintf & sscanf Width Description

No. Width Description sprintf Status sscanf Status
1 (number) Minimum number of characters to be printed. If the value to be printed is shorter than this number, the result is padded with blank spaces. The value is not truncated even if the result is larger. βœ… β˜‘οΈ
2 * In sprintf the _ sign means, that the width is not specified in the format string, but as an additional integer value argument preceding the argument that has to be formatted. In sscanf the _ sign placed after % and before the format specifier reads data of the specified type, but suppresses their assignment. βœ… β˜‘οΈ

sprintf Precision Description

No. .precision Description Status
1 .number For integer specifiers (d, i, o, u, x, X) βˆ’ precision specifies the minimum number of digits to be written. If the value to be written is shorter than this number, the result is padded with leading zeros. The value is not truncated even if the result is longer. A precision of 0 means that no character is written for the value 0. For e, E and f specifiers βˆ’ this is the number of digits to be printed after the decimal point. For g and G specifiers βˆ’ This is the maximum number of significant digits to be printed. For s βˆ’ this is the maximum number of characters to be printed. By default all characters are printed until the ending null character is encountered. For c type βˆ’ it has no effect. When no precision is specified for specifiers e, E, f, g and G, the default one is 6. When no precision is specified for all other kind of specifiers, the default is 1. If the period is specified without an explicit value for precision, 0 is assumed. βœ…
2 .* The precision is not specified in the format string, but as an additional integer value argument preceding the argument that has to be formatted. βœ…

sprintf & sscanf Length Description

No. Length Description sprintf Status sscanf Status
1 h The argument is interpreted as a short int or unsigned short int (only applies to integer specifiers: i, d, o, u, x and X). βœ… β˜‘οΈ
2 l The argument is interpreted as a long int or unsigned long int for integer specifiers (i, d, o, u, x and X), and as a wide character or wide character string for specifiers c and s. βœ… β˜‘οΈ
3 L The argument is interpreted as a long double (only applies to floating point specifiers βˆ’ e, E, f, g and G). βœ… β˜‘οΈ

β€” Developer: RV-304 (@rynortheast) βœ…, Artem Kain (@artemxgod) β˜‘οΈ
β€” Thanks to 21-SCHOOL for provided assignment and special learning conditions ✌️πŸ”₯

Usage

  1. Clone this repository via
    • SSH [email protected]:rynortheast/S21_string.git or
    • HTTPS https://github.com/rynortheast/S21_string.git
  2. Change code base if necessary
  3. Run make test to build project and run main tests
  4. Run make auxTest to build project and run aux tests
  5. Run make s21_string.a to build a static lib

21-string's People

Contributors

rynortheast avatar

Watchers

 avatar

Forkers

shtuder

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.