syang8 wrote: If I have a > struct S { int a; float b; }; > how to initialize a static array of S? > static struct S sarray[] = { ????? }; What book are you reading that doesn't explain POD struct initialization? Note that the "struct" in the definition of sarray[] is a C-ism, not needed in C++. static ...
#include #define MAXSIZE 100 /*max array length*/ int arrlen(int []); int main() { int c, i = 0; int s[MAXSIZE]; while((c=getchar()) != EOF && c != '\n'){ /*while the chars read havn't reached a new line or EOF */ s[i++] = c; /*Read them into an array*/ if(c == '\n'){ s[i++] = c; } } s[i] = '\0'; /* terminate ...