-
Notifications
You must be signed in to change notification settings - Fork 16
add new code part #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| } | ||
| } | ||
|
|
||
| void stringCapitalize(TString *s) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chat-GPT ❤️
| TString stringInitWithCharArr(const char *str) { | ||
| TString s; | ||
| s.length = strlen(str); | ||
| s.capacity = s.length + 1; | ||
| s.data = (char *)malloc(s.capacity * sizeof(char)); | ||
| if (s.data != NULL) { | ||
| strcpy(s.data, str); | ||
| } | ||
| return s; | ||
| } | ||
|
|
||
| void stringDestroy(TString *s) { | ||
| if (s->data != NULL) { | ||
| free(s->data); | ||
| s->data = NULL; | ||
| } | ||
| s->length = 0; | ||
| s->capacity = 0; | ||
| } | ||
|
|
||
| void stringPrint(const TString s) { | ||
| if (s.data != NULL) { | ||
| printf("%s\n", s.data); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Но эти функции же уже есть в коде библиотеки
|
|
||
| void stringPrint(const TString s) { | ||
| if (s.data != NULL) { | ||
| printf("%s\n", s.data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Такой print нельзя, так как буффер строки не заканчивается \0
| s->data[i] = toupper(s->data[i]); | ||
| capitalizeNext = 0; | ||
| } else { | ||
| s->data[i] = tolower(s->data[i]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не нужно уменьшать буквы, функция только делает большими первые буквы
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Readme says: void stringCapitalize(TString *s); - Capitalize the first letter of each word.
|
|
||
| int capitalizeNext = 1; | ||
| for (size_t i = 0; i < s->length; i++) { | ||
| if (isspace(s->data[i])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
И добавьте знаки пунктуации, которые тоже разделяют слова
| - [x] size_t stringCount(TString s, char c); - Count occurrences of a character. | ||
| - [ ] size_t stringCountSubstring(TString s, TString pattern); - Count occurrences of a substring. | ||
| - [ ] void stringCapitalize(TString *s); - Capitalize the first letter of each word. | ||
| - [x] void stringCapitalize(TString *s); - Capitalize the first letter of each word. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Внес свой вклад в развитие проекта добавлением функции, которая безопасно делает заглавной первую букву каждого слова в строке. Это может быть полезно для форматирования текстовых файлов.