aboutsummaryrefslogtreecommitdiff
path: root/count_vowel_string_range.c
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2025-08-27 12:45:33 -0600
committerJack Sangdahl <[email protected]>2025-08-27 12:45:33 -0600
commit4552bcf5a4a356415e248dee3b201f0cea7205bb (patch)
tree9868465918c6a6841b84cd14d66923b993dd9d62 /count_vowel_string_range.c
parentf549305fb5ca531d29dce6c2c091560f44190443 (diff)
downloadleetcode-4552bcf5a4a356415e248dee3b201f0cea7205bb.tar.gz
leetcode-4552bcf5a4a356415e248dee3b201f0cea7205bb.zip
chore: Refactor two_d_arr_init function
Return a pointer to a new struct, rather than initialise objects in an existing struct
Diffstat (limited to 'count_vowel_string_range.c')
-rw-r--r--count_vowel_string_range.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/count_vowel_string_range.c b/count_vowel_string_range.c
index 57eda96..550ce90 100644
--- a/count_vowel_string_range.c
+++ b/count_vowel_string_range.c
@@ -37,13 +37,12 @@ int main() {
char *w1[] = {"aba", "bcb", "ece", "aa", "e"}, *w2[] = {"a", "e", "i"};
int q1i[3][2] = {{0, 2}, {1, 4}, {1, 1}}, rs1;
int q2i[3][2] = {{0, 2}, {0, 1}, {2, 2}}, rs2;
- struct two_d_arr q1, q2;
- two_d_arr_init(&q1, 3, 2, q1i);
- two_d_arr_init(&q2, 3, 2, q2i);
- int *vs1 = vowelStrings((char **)w1, ARRAY_SIZE(w1), q1.arr, q1.row_size,
- q1.col_size, &rs1);
- int *vs2 = vowelStrings((char **)w2, ARRAY_SIZE(w2), q2.arr, q2.row_size,
- q2.col_size, &rs2);
+ struct two_d_arr *q1 = two_d_arr_init(3, 2, q1i);
+ struct two_d_arr *q2 = two_d_arr_init(3, 2, q2i);
+ int *vs1 = vowelStrings((char **)w1, ARRAY_SIZE(w1), q1->arr, q1->row_size,
+ q1->col_size, &rs1);
+ int *vs2 = vowelStrings((char **)w2, ARRAY_SIZE(w2), q2->arr, q2->row_size,
+ q2->col_size, &rs2);
for (int i = 0; i < rs1; i++)
printf("%d ", vs1[i]); // expect: 2 3 0
printf("\n");
@@ -51,5 +50,6 @@ int main() {
printf("%d ", vs2[i]); // expect: 3 2 1
printf("\n");
free(vs1), free(vs2);
- two_d_arr_free(&q1), two_d_arr_free(&q2);
+ two_d_arr_free(q1);
+ two_d_arr_free(q2);
}