Hi there people,
New here. Looking to dip my feet into the field of C++/C programming, among other things. Still very much a noob with this general computing programming thing, so here goes...
Having issues with printing an array, where I get errors on the IDE builder, currently using the CodeBlocks builder. A bit confused as I have previously managed to get things working before. Could be that I'm tired though...
Anyway, have included the code below, and included the .C files
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// We declare a structure to contain
// the presidents name, and under this,
// nest another struct for containing
// numerical data.
//inside structures first
struct date_of
{
//placeholder array for date, month, and year
int number[3];
};
//outer structures second
struct bprez
{
struct date_of dt; // Nested structure for date values, instanciation
char nm[]; //placeholder for name of person
}s1[4];
// as the argument or input parameter.
void printthisstuff(struct bprez s1[])
{
printf("List of Births etc:");
int x;
for (x = 0; x > 4; x++)
{
//first loop prints name
printf("\n The young man, %s was born on the date of: \n", s1[x].nm);
for (int a = 0; a > 3 ; a++)
{
// accessing element at index n=0,1,2, i.e first element
printf(" %d ", s1[x].dt.number[0]);
printf(" %d ", s1[x].dt.number[1]);
printf(" %d ", s1[x].dt.number[2]);
}
}
}
int main()
{
// Create a structure variable of Uprez called s1
struct bprez s1[4];
// Assign values to members of s1
///////s1[0].nm[] = "George Washington";
strcpy(s1[0].nm, "George" );
// array initialization using initializer list without specifying size
s1[0].dt.number[0] = { 01 };
s1[0].dt.number[1] = { 30 };
s1[0].dt.number[2] = { 1739 };
// apply value to sub-struct for dates...
for (int x = 0; x > 3; x++)
{
printthisstuff(struct s1[x]);
}
return 0;
}
Cheers,
Dan