Skip to content

Commit c10c017

Browse files
Merge pull request #3 from electricalgorithm/dev
feat: add llstr2char function
2 parents cef5523 + 497561c commit c10c017

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/llstring.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,25 @@ void append_llstring (LL_StringNode *appended, LL_StringNode *source, u_int16_t
7171
_src->next_letter = appended;
7272
}
7373

74+
char *llstr2char (LL_StringNode *llstring) {
75+
size_t size_of_llstring = ll_strlen(llstring);
76+
char *str = (char *) malloc(sizeof(char) * size_of_llstring);
77+
78+
u_int16_t cursor_char = 0;
79+
LL_StringNode *cursor_ll = llstring;
80+
while (cursor_ll != NULL) {
81+
// Copying the cursor_ll to str[cursor_char]
82+
str[cursor_char] = cursor_ll->character;
83+
// Going to next cursors
84+
cursor_char++;
85+
cursor_ll = cursor_ll->next_letter;
86+
}
87+
// Adding EOL to end of the string
88+
str[cursor_char] = '\0';
89+
return str;
90+
}
91+
92+
7493
/* String Manipulation Functions */
7594
LL_StringNode *ll_strcpy (LL_StringNode* destination, LL_StringNode* source) {
7695
LL_StringNode *_cursor_src = source;
@@ -88,12 +107,9 @@ LL_StringNode *ll_strcpy (LL_StringNode* destination, LL_StringNode* source) {
88107
_cursor_dest = _cursor_dest->next_letter;
89108
_cursor_src = _cursor_src->next_letter;
90109
}
91-
92-
93110
return destination;
94111
}
95112

96-
/* String Manipulation Functions */
97113
LL_StringNode *ll_strncpy (LL_StringNode* destination, LL_StringNode* source, u_int16_t count) {
98114
LL_StringNode *_cursor_src = source;
99115
LL_StringNode *_cursor_dest = destination;

src/llstring.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ typedef struct ll_letter_node {
1717
LL_StringNode* create_llstring (const char[]);
1818
void delete_character (LL_StringNode*, u_int16_t);
1919
void append_llstring (LL_StringNode*, LL_StringNode*, u_int16_t);
20+
char *llstr2char (LL_StringNode*);
2021

2122
/* String Manipulation Functions */
2223
LL_StringNode *ll_strcpy (LL_StringNode*, LL_StringNode*);

0 commit comments

Comments
 (0)