i somehow can't find how to fix the error: "non portable pointer assignment in function main"

#define b break
#define p printf
#define s scanf
main()
{
char M,[9];
int month, day, year;
p("Enter Month:");
s("%d", &month);
p("Enter Day:");
s("%d", &day);
p("Enter Year:");
s("%d", &year);

switch(month)
{ 
case 1: M="January"; b;
case 3: M="March"; b;
case 5: M="May"; b;
case 7: M="July"; b;
case 8: M="August"; b;
case 10: M="October"; b;
case 12: M="December"; b;
}
    if (day != 31)
    p("Invalid Day");

switch(month)
{
case 4: M="April"; b;
case 6: M="June"; b;
case 9: M="September"; b;
case 11: M="November"; b;
}
    if (day != 30)
    p("Invalid Day");
if (month=2)
    if (day != 28)
    p("Invalid Day");
else
    M="February";
if (month>12)
p("Invalid Date");
}


getch();
}

Recommended Answers

All 3 Replies

Hi EarhawkPH,

You have multiple problems here:
Line #6 should most probably char M[9]. Notice the "," in your code ?
Also you cannot say case 1: M="January"; b;
You will have to say strcpy(M, "January") so that the string "January" is copied into your string array.``

Also, try to stop being so "clever" and redefining standard functions like printf, scanf, break. All that does is make your code impossible to read. Obscurity instead of legibility. Not a good tradeoff!

Also, it is 'int main()' and do not use 'getch()' if you want your code to be portable.

Please remember that you are asking experienced C programmers for their valuable time and some free advice ... so probably it is your best interests, to present your problematic code as simply and as clearly as possible :)

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.