Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int strSize(const char* str){ //Дължина на Стринг
- int counter = 0;
- while(*str != '\0'){
- counter++;
- str++;
- }
- return counter;
- }
- void strCopy(char* destination, const char* source){ //Копиране на Стринг
- char* p = destination;
- while(*source != '\0'){
- *p = *source;
- p++;
- source++;
- }
- p = '\0';
- }
- int strCompare(const char* str1, const char* str2){ //Сравняване на Стринг
- if(strSize(str1) != strSize(str2)){
- return (*str1 - *str2) > 0 ? 1 : -1;
- }
- while(*str1){
- if(*str1 != *str2){
- return (*str1 - *str2) > 0 ? 1 : -1;
- }
- str1++;
- str2++;
- }
- return 0;
- }
- char* strConcatenate(char* destination, const char* source){ //Конкатениране на Стринг
- char* str1End = destination + strSize(destination);
- while (*source != '\0') {
- *str1End++ = *source++;
- }
- *str1End = '\0';
- return destination;
- }
- int main(){
- //MAIN ZADACHA 1 - Дължина на Стринг
- /*
- char str[50];
- printf("Enter string: ");
- gets(str);
- printf("%d", strSize(str));
- */
- //MAIN ZADACHA 2 - Сравняване на Стринг
- /*
- char str[50];
- char str2[50];
- printf("Enter first string: ");
- gets(str);
- printf("Enter second string: ");
- gets(str2);
- printf("String compare: %d", strCompare(str, str2));
- */
- //MAIN ZADACHA 3 - Копиране на Стринг
- /*
- char str[50];
- char str2[50];
- printf("Enter first string: ");
- gets(str);
- strCopy(str2, str);
- printf("String 2 is: %s", str2);
- */
- //MAIN ZADACHA 4 - Конкатениране на Стринг
- char str1[50];
- printf("Enter string: ");
- gets(str1);
- char str2[50];
- printf("Enter string: ");
- gets(str2);
- printf("Your concatenated strings: %s", strConcatenate(str1, str2));
- return 0;
- }
Add Comment
Please, Sign In to add comment