Hi, I have been trying to use a struct to hold some const chars that represent a fixed date

The idea is to select a date on a Month Calendar and compare it to the fixed date in the struct so that a MessageBox can show

typedef struct BASEFULL
    char const* bYear(){return "2010";}
    char const* bMonth(){return "October";}
    char const* bLongDay(){return "Saturday";}
    char const* bDay(){return "23";}


This is where the comparison is:

                    BASEFULL mch;
                    MonthCal_GetSelRange(hWndMonthCal, chk);

                    char buf3[30];
                    GetDateFormat(NULL, DATE_LONGDATE, &chk[0], NULL, buf3, 30);

                    char buf[100];
                    strcpy(buf, buf3);
                    strcat(buf, " = ");
                    strcat(buf, mch.bLongDay());
                    strcat(buf, ", ");
                    strcat(buf, mch.bDay());
                    strcat(buf, " ");
                    strcat(buf, mch.bMonth());
                    strcat(buf, " ");
                    strcat(buf, mch.bYear());

                    if(mch.bLongDay() == chk[0].wDayOfWeek)
                        MessageBox(hwndDlg, buf, "MATCH!", 0);

The comparison has an error: "forbidden comparison between pointer and integer"

If I comment out the "if", the message shows correctly. How can I set the comparison up correctly?

Please forgive me if I am being confusing but I am a newbie in win32 and c++
Please help me figure things out with this error.

6 Years
Discussion Span
Last Post by comeugive

You could try having a mapping of strings to numbers and upon entering a string as the key the map returns the value as an integer that the day represents.


The following code is an example of how you could use a map to solve your problem.

#include <iostream>
#include <map>
#include <string>
#include <Windows.h>

using namespace std;

int main(){

	map<string, WORD> myMap; // map where "strings" are used as keys and 16-bit ints are returned
	string arr[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
	map<WORD, string> reverseMap; // just for convenience
	enum {DOW = 7};

	for(int i = 0; i < DOW; i++){
		myMap.insert(pair<string, WORD>(arr[i] , static_cast<WORD>(i) ));
		reverseMap.insert(pair<WORD, string>(static_cast<WORD>(i), arr[i]));

	for( map<string, WORD>::iterator it = myMap.begin(); it != myMap.end(); it++)
		cout << (*it).first << " => " << (*it).second << endl;

	WORD dayOfWeek = static_cast<WORD>(5);

	if( myMap["Saturday"] == dayOfWeek)
		cout << "Today is Saturday!" << endl;

		cout << "Today is not Saturday, but it is " << reverseMap[dayOfWeek] << "!"<< endl;

	return 0;

Woah! That is waaay too complex.

I did find a solution though: I just used SYSTEMTIME members and assigned values to the ones I needed. Now my code is much simpler.

But thanks anyway for at least giving me a reason to rethink my approach...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.