|
The younger brother just learned the C language. I encountered several problems in the recent code and couldn't solve it for two days. I was really depressed. I hope the heroes will help:
#include <stdio.h>
#define DATATYPE1 int
#define MAXSIZE 100
typedef struct
{
DATATYPE1 datas [MAXSIZE];
int last;
} SEQUENLIST;
main ()
{
SEQUENLIST squn1;
squn1.datas [MAXSIZE] = {0,1,2,3,4}; // Why not write like this
Ranch
}
Why is it not possible to assign squn1.datas in this code? I see the same in the textbook. I always get the following error after assignment
D:\vc\MSDev98\MyProjects\chapter2\sequenlist.cpp (58): error C2059: syntax error: '('
D:\vc\MSDev98\MyProjects\chapter2\sequenlist.cpp (58): error C2143: syntax error: missing ';' before '('
D:\vc\MSDev98\MyProjects\chapter2\sequenlist.cpp (58): error C2143: syntax error: missing ';' before ')'
D:\vc\MSDev98\MyProjects\chapter2\sequenlist.cpp (76): warning C4508: 'main': function should return a value; 'void' return type assumed
Error executing cl.exe.
However, I changed it to squn1.datas [0] = 0; in this way, the assignment of a single element to a single element is fine. It is also why the assignment is not possible. I hope heroes will help. |
|