#include<stdio.h> #define n 3 struct body { double p[3];//position double v[3];//velocity double a[3];//acceleration double radius; double mass; }; struct body bodies[n]; int main() { int a, b; for(a = 0; a < n; a++) { for(b = 0; b < 3; b++) { bodies[a].p[b] = 0; bodies[a].v[b] = 0; bodies[a].a[b] = 0; } bodies[a].mass = 0; bodies[a].radius = 1.0; } return 0; }
this works fine. your question was not very clear by the way, so match the layout of your source code with the above.
Related Posts:
- typedef struct vs struct definitions [duplicate]
- Why should we typedef a struct so often in C?
- Why should we typedef a struct so often in C?
- typedef struct vs struct definitions [duplicate]
- How do I determine the size of my array in C?
- dereferencing pointer to incomplete type
- char *array and char array[]
- How do I create an array of strings in C?
- “Expected expression before ‘ { ‘ token”
- C pointers and arrays: [Warning] assignment makes pointer from integer without a cast
- How to print the array?
- “error: assignment to expression with array type error” when I assign a struct field (C)
- How do I create an array of strings in C?
- Return char[]/string from a function [duplicate]
- Difference between a Structure and a Union
- Why am I getting “array initializer must be an initializer list or string literal”?
- How to initialize a struct in accordance with C programming language standards
- Using Dynamic Memory allocation for arrays
- Incompatible implicit declaration of built-in function ‘malloc’
- Finding the length of a Character Array in C
- Return char[]/string from a function
- How to print a char array in C through printf?
- How to clear all the elements of array in C?
- What is the cause of flexible array member not at end of struct error?
- Zero an array in C code
- Passing an array by reference in C?
- Excess elements in char array initializer error
- size of struct in C
- How to properly malloc for array of struct in C
- Why am I getting this error: “data definition has no type or storage class”?
- I’m getting “Invalid Initializer”, what am I doing wrong?
- Convert char array to string use C
- Iterate through a C array
- What is the difference between char array and char pointer in C?
- Scanning Multiple inputs from one line using scanf
- Initializing array of structures
- typedef struct pointer definition
- The difference between char * and char[] [duplicate]
- What causes a segmentation fault (core dump) to occur in C?
- uint8_t vs unsigned char
- How to use symbols of extended ASCII table in C?
- What is the difference between ++i and i++?
- Using boolean values in C
- What does “collect2: error: ld returned 1 exit status” mean?
- What can be the reasons of connection refused errors?
- Why am I getting “void value not ignored as it ought to be”?
- 1 = false and 0 = true?
- Get a substring of a char*
- What causes the Broken Pipe Error?
- Why does the terminal show “^[[A” “^[[B” “^[[C” “^[[D” when pressing the arrow keys in Ubuntu?
- Why is the gets function so dangerous that it should not be used?
- Write to .txt file?
- What does “collect2: error: ld returned 1 exit status” mean?
- Warning comparison between pointer and integer
- What does #pragma once mean in C? [duplicate]
- Connect: Socket operation on non-socket
- munmap_chunk(): invalid pointer
- C read file line by line
- No Symbol Table using GDB on Compiled Programs
- What is char ** in C?
- where does stdio.o live in linux machine?
- How do I lowercase a string in C?
- warning: expression result unused
- conflicting types error when compiling c program using gcc
- Get the current time in C
- error: indirection requires pointer operand (‘int’ invalid)
- What is a file with extension .a?
- error: indirection requires pointer operand (‘int’ invalid)
- Valgrind: Invalid read of size 1
- Encrypt with private key and decrypt with public key
- How to create an array of strings in C?
- strcmp giving segmentation fault
- What does “pointer being freed was not allocated” mean exactly?
- Initialization from incompatible pointer type warning when assigning to a pointer
- How to use timer in C?
- Convert char array to a int number in C
- What is the difference between stdin and STDIN_FILENO?
- Allocating string with malloc
- How to simply convert a float to a string in c?
- How to copy a char array in C?
- hash function for string
- What happens during a “relocation has invalid symbol index” error?
- Double pointer array in c++
- Can I create an Array of Char pointers in C?
- Error: “Access not within mapped region at address” (Valgrind)
- How to convert string to float?
- C char array initialization
- How does the fscanf function work?
- Math constant PI value in C
- char array not assignable
- Warning: comparison of distinct pointer types
- The code does not execute properly. Try to figure out why
- ld.exe: cannot open output file … : Permission denied
- How to read from input until newline is found using scanf()?
- getline() vs. fgets(): Control memory allocation
- Segmentation fault- strcat
- C: warning: excess elements in array initializer; near initialization for ‘xxx’ ; expects ‘char *’, but has type ‘int’
- Initializing 2D char array in C
- Error: Conversion to non-scalar type requested
- segmentation fault with strcpy [duplicate]