Can you combine the pointer array and the array pointer?

Asked 2 years ago, Updated 2 years ago, 74 views

void com() {
    struct TTT {
        char isDup[10];
        char readData[10];
        struct TTT* link[9];
    };
     struct TTT case1;
     char* data;

     data = read();
     for (int i = 0; i < 9; i++) {
         case1.readData[i] = data[i];
         case1.isDup[i] = data[i];
     }

         case1.readData[9] = '\0';
         case1.isDup[9] = '\0';
         for (int i = 0; i < 9; i++)
             for (int j = 0; j < 10; j++)
                 *case1.link[i]->readData[j] = case1.readData[j];*

         for (int i = 0; i < 9; i++)
             for (int j = 0; j < 9; j++)
             {
                 if (case1.isDup[j] == '0')
                 {
                     case1.isDup[j] = '2';
                     case1.link[i]->readData[j] = '2';
                    i++; j = 0;
                 }
             }

}

There's an error *case1.link[i]->readData[j] = case1.readData[j];* An error occurred while reading the character in the string in this part. That's the error There are several pointers that point to an array, so we need an array of pointers. Each pointer points to an array. How can I modify it to do that? I'm sorry for the insufficient question

c++ c data-structure

2022-09-22 10:34

1 Answers

I don't think I can give you a definite solution, but...

Based on my poor coding skills, it could be a bit dangerous.

If you look at the top,

struct TTT {
    char isDup[10];
    char readData[10];
    struct TTT* link[9];
};

If you look at the code,

Create a structure called TTT (declaration?),

On top of that, you have a TTT like yourself as a member variable.

This is a very recursive structure

If you write it like this,

The fact that the member variable of the structure TTT has a nine-space array such as TTT (self).

In that arrangement, again and again

It's like this.

In a structure called TTT

Black is isDup[10] and readData[10];

Red is link with TTT, which is itself, as a member array variable (?) in the structure TTT.

I'm not a developer in the field, I'm a student. I wonder if there's any reason to have this kind of structure. (I'm sure there is, right?))

If you look at the c++ debugger in Visual Studio 2017, if you go above link (double) of link, Unable to read memoryThe word appears.

Like this...

It has a very strange structure.

I can't give you fancy, fancy solutions and code like those in the field, but...

I wrote down my answer with my sincere heart.


2022-09-22 10:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.