Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7613989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:17:19+00:00 2026-05-31T02:17:19+00:00

Fixed. include main() { int n; int i; char tempMonth[255]; //Used to store the

  • 0

Fixed.

include

main()
{
    int n;
    int i;
    char tempMonth[255]; //Used to store the month until checked

    scanf("%d", &n);

    struct date *list;

    list = (struct date *)malloc((n * sizeof(struct date)));

    for(i = 0; i < n; i++)
    {
        scanf("%s %d %d", tempMonth, &list[i].day, &list[i].year);
        list[i].month = getMonth(tempMonth);
    }

    convertFullYear(list, n);

    qsort(list, n, sizeof(struct date), (compfn)sortDates);

    convertSmallYear(list, n);

    for(i = 0; i < n; i++)
    {
        printf("%s %d %02d\n", months[list[i].month], list[i].day, list[i].year);
    }

    char *pos = (char*) bsearch(Jan, list, sizeof(list), sizeof(Jan), findJan);
}

As you can see I have put what I think is correct to call bsearch, however if it is right i’m not sure where to go from here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:17:21+00:00Added an answer on May 31, 2026 at 2:17 am

    If you’re searching for a specific date, then use a struct date as a key:

    struct date Jan;
    Jan.month = 0;
    Jan.year = 00;
    Jan.day = 1;
    

    Then you can use your sortDates function (you should rename it to compareDates):

    struct date* pos = bsearch(
        &Jan, /* pointer to the structure above */
        list, /* pointer to your array */
        n, /* number of elements in your array */
        sizeof(struct date), /* size of each element */
        (compfn)sortDates /* compare function */
    );
    

    See also http://www.cplusplus.com/reference/clibrary/cstdlib/bsearch/ and http://en.cppreference.com/w/cpp/algorithm/bsearch for further examples.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

File main2.cpp: #include poly2.h int main(){ Poly<int> cze; return 0; } File poly2.h: template
#include<iostream> #include<fstream> #include<cstdlib> #include<string> using namespace std; **int main() { double write(); double read();
I have the following code: #include <iostream> #include Student.h <-- fixed the problem #include
My file looks like: 123456789 My code gives me segmentation fault: #include <stdio.h> int
Code #include <OOLua/oolua.h> class foo { public: int bar(); }; OOLUA_CLASS_NO_BASES(foo)//class has no bases
Here is my code: #include <iomanip> #include <fstream> #include <iostream> using namespace std; int
I'm testing the following code: #include <iostream> #include <vector> #include <algorithm> #include <ctime> int
Fixed: See notes at bottom I am implementing a generic class that supports two
By fixed vector I mean a static list of values, like 1 through 24.
So I just fixed a bug in a framework I'm developing. The pseudo-pseudocode looks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.