Pass multiple strings to function C

I’m learning the basics and principles of C.
I came now to pointers, strings and structs.
Now I’m working on this code to pass arrays’ content to functions.
I have this code to pass content of different arrays to function.
What I succeeded to accomplish is:

1.How to pass one complete string because it’s considered as one element of the array.
2.How to pass array of char and ints.

The issues I have now:

1.How to pass arrays of multiple strings to functions.
2.How to assign a pointer to the arrays to pass them also to functions.

This is my code so far:
There are commented parts to show the work I done in the code, I’m actually a beginner in C. I just feel that it’s nice to leave arranged commented lines so the readers understand my issue more.

#include<stdio.h>
#include<string.h>
#include<stdint.h>

    void print_array(char *arr,int8_t cnt);
    void print_array(char *arr,int8_t cnt)
    {
        int_fast8_t i;
        printf("Number of elements is: %d\n",cnt);
        for (i=0;i<cnt;i++)
        {
            printf("Elements of array: %s\n",arr);
        }
    }

    void print_len (char *arr,int8_t cnt);

    void print_len (char *arr,int8_t cnt)
    {
        char i,l=strlen(arr);
            for (i=0;i<cnt;i++)
        {
            printf ("%d\n",strlen(arr));
        }
    }


int main()
{
    char  array_1 [] = {1,2,3,4,5,6,7,8};
    char  array_2 [] = {'1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G'};
    char *array_3 [] = {"1st","2nd","3rd","4th","5th","6th"};
    char *array_4 [] = {"Many of the designations used by manufacturers"};
    char *array_5 [] = {"mm","End of Multiple Strings Array","simple bluetooth connection",
    "datalogging purposes and accessing recorded data","THE OPERATING ENVIRONMENT"};
    //int8_t *array_pointer[3]=(char*){&array_1,&array_2,&array_3};
    int8_t cnt1 = sizeof(array_1)/sizeof(array_1[0]);
    int8_t cnt2 = sizeof(array_2)/sizeof(array_2[0]);
    int8_t cnt3 = sizeof(array_3)/sizeof(array_3[0]);
    int8_t cnt4 = sizeof(array_4)/sizeof(array_4[0]);
    int8_t cnt5 = sizeof(array_5)/sizeof(array_5[0]);
    int8_t len1,len2,len3,len4,len5,i,t=0,x=0;
    //print_len(*array_3,cnt3);
    //print_len(*array_5,cnt5);
    //printf("Number of chars int the string#%d is: %d\n",i,t);


    /*for (i=0;i<cnt5;i++)
    {
        printf ("%s\n",array_5[i]);
    }*/


    //print_array(array_pointer[0],cnt1);
    //print_array(array_1,cnt1);
    //print_array(array_2,cnt2);
    //print_array(*array_3,cnt3);
    //print_array(*array_4,cnt4);
    print_array(*array_5,cnt5);
    return 0;
}

if you want help, consider fixing the formatting of your code.. it's unusable as currently provided (just a SINGLE HUGE long line)

J-M-L: if you want help, consider fixing the formatting of your code.. it's unusable as currently provided (just a SINGLE HUGE long line)

+1. No way I'm trying to read that.

OK, sorry :)

Code updated;

so what do you think this would mean?

    //int8_t *array_pointer[3]=(char*){&array_1,&array_2,&array_3};

Editing done.

No I mean is this one of your attempt to do something ? and if so, what were you trying to do

(deleted)

why did you modify the code you posted??? now comments below don't make sense anymore...

what you had posted originally is the same ask you had on stackOverflow

what's going on now??

J-M-L: No I mean is this one of your attempt to do something ? and if so, what were you trying to do

I wanted to declare a pointer to the arrays and pass them to function by indexing.

spycatcher2k: Is it arduino code?

No, but it's simple C so I think it would be the same as sending strings to LCD.

J-M-L: why did you modify the code you posted??? now comments below don't make sense anymore...

I thought you wanted me to remove them to get more readable code.

It's OK now I just want to solve this piece of code the other lines are for different types of arrays and it's the same procedure and I compiled these arrays and I stopped in array of multiple strings.

J-M-L: what you had posted originally is the same ask you had on stackOverflow

what's going on now??

I firstly posted the code in stack overflow but didn't get the solution. And posted in this forum, to get more ideas and see other solutions.

Is this a problem to post the same issue on different forums. I'm sorry I didn't know until now, I one time posted the same thread in the same forum because I was waiting for days and no response, so I posted another one.

No it's not a pb to post at different forum (only once here though) - usually not getting an answer is a sign that your ask is confusing, like re-edting and changing the full code you posted originally... then we are lost as anyone reading that thread...

does this help?

char helloString[] = "Hello";
char wolrdString[] = "World!";
char*arrayOfPointersToCharStrings2[] = {helloString, wolrdString};

also you don't want to do

void print_len (char *arr,int8_t cnt); void print_len (char *arr,int8_t cnt);

before the actual code of your function

J-M-L:
No it’s not a pb to post at different forum (only once here though) - usually not getting an answer is a sign that your ask is confusing, like re-edting and changing the full code you posted originally… then we are lost as anyone reading that thread…

does this help?

char helloString[] = "Hello";

char wolrdString = “World!”;
char*arrayOfPointersToCharStrings2 = {helloString, wolrdString};

That’s exactly what I did:

These are the arrays and the pointer array to multiple arrays:

    char  array_1 [] = {1,2,3,4,5,6,7,8};
    char  array_2 [] = {'1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G'};
    char *array_3 [] = {"1st","2nd","3rd","4th","5th","6th"};
    char *array_4 [] = {"Many of the designations used by manufacturers"};
    char *array_5 [] = {"mm","End of Multiple Strings Array","simple bluetooth connection",
    "datalogging purposes and accessing recorded data","THE OPERATING ENVIRONMENT"};

     int8_t *array_pointer[3]=(char*){&array_1,&array_2,&array_3};

J-M-L:
also you don’t want to do

void print_len (char *arr,int8_t cnt);
void print_len (char *arr,int8_t cnt);

before the actual code of your function

Why? Do you mean the position for the prototype of the function and the function declaration?
Or the this function is not necessary? I find this function similar to the function print_array. Because it sends series of ints to the length of each string in the strings array. It’s about the same concept I want to accomplish with arrays.

the prototype is not necessary if you define the function right there afterwards. could make sense in a .h for example if you use the functions elsewhere

char array_1 [] = {1,2,3,4,5,6,7,8}; char array_2 [] = {'1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G'}; char *array_3 [] = {"1st","2nd","3rd","4th","5th","6th"}; char *array_4 [] = {"Many of the designations used by manufacturers"}; char *array_5 [] = {"mm","End of Multiple Strings Array","simple bluetooth connection", "datalogging purposes and accessing recorded data","THE OPERATING ENVIRONMENT"};

int8_t array_pointer[3]=(char){&array_1,&array_2,&array_3};

so now that you have modified the original code in the post at the Top, who understands where this comes from??

and do you think

int8_t array_pointer[3]=(char){&array_1,&array_2,&array_3};

is the same as

char*arrayOfPointersToCharStrings2[] = {helloString, wolrdString};

J-M-L: the prototype is not necessary if you define the function right there afterwards. could make sense in a .h for example if you use the functions elsewhere

OK thanks for the information :)

so now that you have modified the original code in the post at the Top, who understands where this comes from??

and do you think

int8_t array_pointer[3]=(char){&array_1,&array_2,&array_3};

is the same as

char*arrayOfPointersToCharStrings2[] = {helloString, wolrdString};

NO, not the same! There are differences. Anyway I tried different forms to declare this pointer to arrays.

You understand that array1 and 2 are similar but not array3 right?

Of course, array1 is ints and array2 is chars. But they are similar in process I can read them by a function call.

Array3 is same array5 multiple strings in one array which is the problem I have in reading from a function. Array4 is considered as one element so it reads directly.

What I want to learn is how to manage multiple strings array by a function.

Thank you very much for support:

I found the answer.

    void print_array(char *arr[],int8_t cnt);
    void print_array(char *arr[],int8_t cnt)
    {
        int8_t i;
        printf("Number of elements is: %d\n",cnt);
        for (i=0;i<cnt;i++)
        {
            printf("Elements of array: %s\n",arr[i]);
        }
    }
 
print_array(array_5,cnt5);

Of course, array1 is ints and array2 is chars. But they are similar in process I can read them by a function call.

no array1 and array2 are chars as you define them as chars. 1,2,3 are just ASCII letters you can't represent in print but nevertheless chars

so array 1 and 2 are same type, while array 3 was already an array of pointers to chars arrays

void print_array(char *arr[],int8_t cnt); void print_array(char *arr[],int8_t cnt)

Good - but again you don't need to write the prototype just before the function. it's totally useless.