Mein Vorhaben ist, wie in der Ueberschrift erwaehnt, meinen C Code in C++ Code umzuschreiben. Ist eine einmalige Sache, aber mein Unwissen in C++ hilft mir da nicht gerade. Koennte vielleicht jemand so freundlich sein und mir ein wenig helfen?
Hier mal einen der Codeabschnitte:
Alles anzeigen
und hier noch eine Headerdatei:
Alles anzeigen
Hier mal einen der Codeabschnitte:
C-Quellcode
- #include <stdio.h>
- #include <stdlib.h>
- #include "date.h"
- mdate create_d(unsigned day, unsigned month, unsigned year)
- {
- //mdate* date = (mdate*)malloc(sizeof(mdate));
- mdate date;
- date.day=day;
- date.month=month;
- date.year=year;
- return date;
- }
- mdate copy_d(mdate d)
- {
- return create_d(d.day,d.month,d.year);
- }
- int datecmp( const mdate *d1, const mdate *d2)
- {
- if (d1->year < d2->year)
- return -1;
- if (d1->year > d2->year)
- return 1;
- //year is equal
- if (d1->month < d2->month)
- return -1;
- if (d1->month > d2->month)
- return 1;
- //year and month are equal
- if (d1->day < d2->day)
- return -1;
- if (d1->day > d2->day)
- return 1;
- //the dates are equal
- return 0;
- }
- void print_d(mdate d)
- {
- printf("%u.%u.%u",d.day,d.month,d.year);
- }
und hier noch eine Headerdatei:
Quellcode
- #ifndef __DATE_H__
- #define __DATE_H__
- /* a struct to represent a date! of course there is an existing implementation in the C standard :)
- * */
- struct date_{
- unsigned year;
- unsigned month;
- unsigned day;
- } ;
- typedef struct date_ mdate;
- /* creates a date, currently their is no check, whether the given date is valid; 31.02.2000 would make no sense :)
- * */
- mdate create_d(unsigned day, unsigned month, unsigned year);
- mdate copy_d(mdate d);
- /*allows to compare two dates, the function returns
- * 0 if the dates are equal
- * 1 if d1 > d2
- * -1 otherwise
- * */
- int datecmp(const mdate *d1, const mdate *d2);
- /*prints the date to stdout day.month.year*/
- void print_d(mdate d);
- #endif