Re: Why not work is logical?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



#include <stdio.h>

#define URI_MAX 512
#define a 3

int main()
{
    unsigned int link_x=2;
    int contador_x;
    int contador_y;

    char pointer_links[link_x][a][URI_MAX];

    snprintf (pointer_links[0][0], URI_MAX, "http://www.gcc.com";);
    snprintf (pointer_links[0][1], URI_MAX, "http://wwww.PPSON.com";);
    snprintf (pointer_links[0][2], URI_MAX, "http://www.hpc.com";);

    for (contador_x = 0; contador_x < link_x ; contador_x++)
        for (contador_y=0; contador_y < a; contador_y++)
            printf ("LINK[%u][%u] = %s\n",
                    contador_x,contador_y,
                    pointer_links[contador_x][contador_y]);

}

On Apr 15, 2006, at 8:14 AM, Fran wrote:

Hello,
This do not work.

{
#define URI_MAX 512
#define a 3

unsigned int link_x=2;
char (*link)[][][URI_MAX];

...
link = (char (*)[link_x][a][URI_MAX]) malloc (sizeof (char) * link_x * (a) * (URI_MAX));

{
char (*pointer_links)[link_x][a][URI_MAX] = (char (*)[link_x][a] [URI_MAX]) link;

snprintf (*(pointer_links)[0][0], URI_MAX, "http://www.gcc.com";);
snprintf (*(pointer_links)[0][1], URI_MAX, "http://wwww.PPSON.com";);
snprintf (*(pointer_links)[0][2], URI_MAX, "http://www.hpc.com";);
...

for (contador_x = 0; contador_x < link_x ; contador_x++)
     {
        for (contador_y=0; contador_y < a; contador_y++)
          {
printf ("LINK[%u][%u] = %s\n",contador_x,contador_y,* (pointer_links)[contador_x][contador_y]);
          }
      }
}

}

Output, see PPSN not PPSON.
LINK[0][0] = http://www.gcc.com
LINK[0][1] = http://www.PPSN.com
LINK[0][2] = http://www.hpc.com
...
In general this method do not work in arrays with n > 1.

Why do not work? GCC do not warn while compile about errors.

Thanks in advance.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux