mardi 23 juin 2020

Trying to concatenate array of c-strings with delimiter

Here is my code

int main(int argc, char *argv[]) {

    char const *strings[10] = {"dhh", "aci", "cdh"};
    join_def(strings, 'l');

    return EXIT_SUCCESS;
}


// part 1 read lines
void join_def(char const **strings, char delim) {
    char *t = new char[100];
    //int length = 0;
    t[0] = '\0';
    int x = sizeof(strings);
    std::cout << delim << std::endl;

    for (int i = 0; i < x; i++) {
        int size = 0;
        while(strings[i][size]!='\0'){
            size++;
            std::cout << strings[i][size] << std::endl;
        }
    }
}

I have spent hours now I just can't get to concatenate it For this task, I cannot use cstring or anything other than iostream so please don't suggest.

The output needs to be a c-string = "dhhlacilcdh"

Aucun commentaire:

Enregistrer un commentaire