4 Replies - 442 Views - Last Post: 02 April 2013 - 03:40 PM Rate Topic: -----

#1 makanayoru  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 02-April 13

view specific record based on current date (month, year)

Posted 02 April 2013 - 02:54 AM

hello guys.. A beginner in c++ here.

I need to view a record based on the current month. When the user run this program it will automatically view a report which have the same month with the current report

the comparison will be based on the expiry. If the expiry is "apr 2013", this report will be display else "no expired road tax for this month"

I tired looking around but can't find the function to retrieve the current month for comparison.

Below is my coding for the report without any date comparison function.

#include <stdio.h>

struct  cardata {
			int carNum;
			char regNum[10];
			char make[20];
			char model[20];
			char engine;
			char capacity[10];
			char expiry[10];   //(mmm yyyy)
		    } car;



main()
{
  FILE *rec_ptr;
  int vehicleNum;
  char reply = 'Y';

  if ((rec_ptr = fopen("car.db", "r+")) == NULL)
	printf("File could not be opened.\n");
  else
      while (toupper(reply) == 'Y')
      {
      clrscr();

      printf("Enter vehicle #: ");
      scanf("%d", &vehicleNum);

      fseek(rec_ptr, vehicleNum*sizeof(struct cardata), SEEK_SET);
      fread(&car, sizeof(struct cardata), 1, rec_ptr);
      if (strlen(car.regNum) > 0)
	  {

	  int amt;
	  int i = atoi(car.capacity);

	  amt = (i/100) * 2.25;

	   fflush(0);

	   gotoxy(15,3);printf("Vehicle details");
	   gotoxy(8,4);printf("Registration no.     : %s\n", car.regNum);
	   gotoxy(8,5);printf("Make		    : %s\n", car.make);
	   gotoxy(8,6);printf("Model     	    : %s\n", car.model);
	   gotoxy(8,7);printf("Engine type 	    : %c\n", car.engine);
	   gotoxy(8,8);printf("Engine capacity      : %s\n", car.capacity);
	   gotoxy(8,9);printf("Tax expiry date      : %s\n", car.expiry);
	   gotoxy(8,10);printf("Road tax amount      : %d\n", amt);
	  }

      else
	   printf("\nNo data in selected record.\n\n");

      printf("\n\nContinue (y/n)? ");
      reply = getche();

      }

  fclose(rec_ptr);

  return 0;

}




Please help me!!

thank you...

Is This A Good Question/Topic? 0
  • +

Replies To: view specific record based on current date (month, year)

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3589
  • View blog
  • Posts: 11,157
  • Joined: 05-May 12

Re: view specific record based on current date (month, year)

Posted 02 April 2013 - 05:20 AM

localtime() should work for you even though you are using that ancient Turbo C compiler.

Here's the C++ reference, but you can find equivalent C man pages:
http://en.cppreferen...ono/c/localtime

This post has been edited by Skydiver: 02 April 2013 - 05:21 AM

Was This Post Helpful? 0
  • +
  • -

#3 makanayoru  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 02-April 13

Re: view specific record based on current date (month, year)

Posted 02 April 2013 - 05:31 AM

View PostSkydiver, on 02 April 2013 - 05:20 AM, said:

localtime() should work for you even though you are using that ancient Turbo C compiler.

Here's the C++ reference, but you can find equivalent C man pages:
http://en.cppreferen...ono/c/localtime


Thank you for the quick reply..

I don't get it.. how do I compare it?

I try this code for testing but nothing's printed
    time_t rawtime;
    struct tm * timeinfo;
    char month [80];
    char mth [10] = "April";
    time ( &rawtime );
    timeinfo = localtime ( &rawtime );
    strftime (month,80,"%B", timeinfo);




  //  printf("Month : %s\n", month);

    if(month == mth)
    printf("apr");



Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3589
  • View blog
  • Posts: 11,157
  • Joined: 05-May 12

Re: view specific record based on current date (month, year)

Posted 02 April 2013 - 03:00 PM

In C, you can't compare strings using the equality operator as you are using on line 14. You'll need to use strcmp().
Was This Post Helpful? 0
  • +
  • -

#5 David W  Icon User is offline

  • DIC supporter
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,788
  • Joined: 20-September 08

Re: view specific record based on current date (month, year)

Posted 02 April 2013 - 03:40 PM

View Postmakanayoru, on 02 April 2013 - 04:54 AM, said:

hello guys.. A beginner in c++ here.

...


If you are beginning C++ ... then why are you using all C style coding?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1