Jump to content

Bad structure? [C]

- - - - -

  • Please log in to reply
2 replies to this topic

#1
charles-eng

charles-eng

    Learning Programmer

  • Members
  • PipPipPip
  • 39 posts
Hi, I 've been trying to compile a program that uses the following structure but i keep getting errors. What's wrong?

struct node
{
char map[3][3]={{0,0,0},{0,0,0},{0,0,0}};
struct node *father;
struct node *nextLev;
nextLev=NULL;
father=NULL;
};

Thanks in advance.

#2
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
  • Programming Language:Java, C#, PHP
  • Learning:C, C++, C#, PHP, Transact-SQL, Assembly, Scheme
struct node
{
char map[3][3];// = {{0,0,0},{0,0,0},{0,0,0}};
struct node *father;
struct node *nextLev;
};

I don't think you can do initialization in the structure definition? Someone can correct me if I'm wrong.

This compiles:

#include <stdio.h>
#include <stdlib.h>

struct node
{
char map[3][3];// = {{0,0,0},{0,0,0},{0,0,0}};
struct node *father;
struct node *nextLev;
};

int main()
{
    struct node n;
    int x;
    int y;
    for (x = 0; x < 3; x++) {
        for ( y = 0; y < 3; y++) {
            n.map[x][y] = 0;
        }
    }
    return 0;
}




#3
charles-eng

charles-eng

    Learning Programmer

  • Members
  • PipPipPip
  • 39 posts
Thanks, it was that. You cannot initialize structures in C.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users