Hi i've just started to use constructors and I'm having some problems with the following code with data not saving(saving to the correct place)

please Help :(

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <ctype.h>



typedef struct details // struct for all data

{

        char name[50][50];                  

        char card[50][16];                                      

        long sort[50], acco[50];                              

        int  pin[50];                                              

} DETAILS;



void info();





int main() 

{

     DETAILS dt;

     strcpy(dt.name[0],"SAM BERWICK");

     dt.sort[0] = 102030;

     dt.acco[0] = 12345678;

     strcpy(dt.card[0],"1234567812345678");

     dt.pin[0] = 1234;

     

     strcpy(dt.name[1],"DAN BERWICK");

     dt.sort[1] = 302010;

     dt.acco[1] = 87654321;

     strcpy(dt.card[1],"8765432187654321");

     dt.pin[1] = 4321;

     info();

     

}



void info()

{

     DETAILS dt;

     printf("Details n1\n");

     printf("%d",dt.sort[0]);

     system("pause");

}

Ooops please remove this one.

Not sure why you have fifty of everything...

char name[50][50];

Why don't you create an array of structures instead of hard coding fifty elements into your structure members.

DETAILS dt[50];

Hi i've just started to use constructors and I'm having some problems with the following code with data not saving(saving to the correct place)

please Help :(

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <ctype.h>



typedef struct details // struct for all data

{

        char name[50][50];                  

        char card[50][16];                                      

        long sort[50], acco[50];                              

        int  pin[50];                                              

} DETAILS;



void info();





int main() 

{

     DETAILS dt;

     strcpy(dt.name[0],"SAM BERWICK");

     dt.sort[0] = 102030;

     dt.acco[0] = 12345678;

     strcpy(dt.card[0],"1234567812345678");

     dt.pin[0] = 1234;

     

     strcpy(dt.name[1],"DAN BERWICK");

     dt.sort[1] = 302010;

     dt.acco[1] = 87654321;

     strcpy(dt.card[1],"8765432187654321");

     dt.pin[1] = 4321;

     info();

     

}



void info()

{

     DETAILS dt;

     printf("Details n1\n");

     printf("%d",dt.sort[0]);

     system("pause");

}

Where's the constructor problem? I didn't quite catch you..If you are trying to write a function that'll print your struct's variable data then you have to pass a struct parameter in your function..

Never mind about that I managed to sort it out. In C how would I round a number to the nearest 10.

Its pretty straight forward

#include <stdio.h>
#include <math.h>

int main()
{
	double val = 123.33;

	fprintf(stdout, "rounded->%d\n", lround(val/10.0) * 10);
	return 0;
}
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.