Hi all,

Could someone tell me what's wrong with this code? I'm using MS Visual C++ IDE and I'm getting a syntax error when compiling this program.

#include<stdio.h>

struct _test
{
    int iNum[5];
};

typedef struct _test test;

int main(int argc, char** argv)
{
    test newTest;

    newTest.iNum = {1,2,3,4,5};
    printf("%d\n",newTest.iNum[0]);
    printf("%d\n",newTest.iNum[1]);
    printf("%d\n",newTest.iNum[2]);
    printf("%d\n",newTest.iNum[3]);
    printf("%d\n",newTest.iNum[4]);
}

Just because the array is a member of a structure doesn't mean you can suddenly assign to it. Array assignment isn't allowed in C, but you can do a structure initialization to the same effect:

test newTest = {1,2,3,4,5};
commented: omg I just noticed your new site. It's soooo cute, with its new colour scheme and the javascript in the code. :) +11
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.