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 question.(5)

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

ITtutoria

ITtutoria Logo ITtutoria Logo

ITtutoria Navigation

  • Python
  • Java
  • Reactjs
  • JavaScript
  • R
  • PySpark
  • MYSQL
  • Pandas
  • QA
  • C++
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA
Home/ Questions/Is there any solution for the warning: control reaches end of non-void function [-wreturn-type] error?
Next
Answered
Lorraine O'Brien
  • 17
Lorraine O'Brien
Asked: May 18, 20222022-05-18T16:06:14+00:00 2022-05-18T16:06:14+00:00In: cpp

Is there any solution for the warning: control reaches end of non-void function [-wreturn-type] error?

  • 17

. Advertisement .

..3..

. Advertisement .

..4..

I get the error: warning: control reaches end of non-void function [-wreturn-type] when I try to run the program below:

/*date difference calculator*/
 
 #include <stdio.h>
 
 int main()
 {
  int Date1 = 0, Date2 = 0, Dif, F, L, D1, D2, M1, M2, Y1, Y2;
  int x[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  int y[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  char A1, A2, B1, B2;
 
 /*input first date*/
 
  fprintf (stderr , "Enter first date,in the form <day>/<month>/<year> or <day>-<month>-<year>.\nWhere <day>,<month> and <year> are integers:\n");
  (scanf("%i%c%i%c%i", &D1, &A1, &M1, &B1, &Y1));
 
 /*check first date*/
 
  if (!(Y1 % 4)) x[2]=29;
  while ((Y1 < 1 || (Y1 > 9999)) || (M1 < 1 || M1 > 12) || (D1 < 1 || D1 > x[M1]) || (A1 != B1) || ((A1 != '/') && (A1 != '-'))) 
  {
  fprintf (stderr, "Incorrect format, re-enter date:\n");
  scanf("%i%c%i%c%i", &D1, &A1, &M1, &B1, &Y1);
  if (!(Y1 % 4)) x[2]=29;
  }
 
 /*print first date*/
 
  fprintf (stderr, "First date = %i%c%i%c%i\n", D1 , A1 , M1 , B1 , Y1);
 
 /*input second date*/
 
  fprintf (stderr , "Enter second date,in the form <day>/<month>/<year> or <day>-<month>-<year>.\nWhere <day>,<month> and <year> are integers:\n");
  (scanf("%i%c%i%c%i", &D2, &A2, &M2, &B2, &Y2));
 
 /*check second date*/
 
  if (!(Y2 % 4)) y[2]=29;
  while ((Y2 < 1 || (Y2 > 9999)) || (M2 < 1 || M2 > 12) || (D2 < 1 || D2 > y[M2]) || (A2 != B2) || ((A2 != '/') && (A2 != '-'))) 
  {
  fprintf (stderr, "Incorrect format, re-enter date:\n");
  scanf("%i%c%i%c%i", &D2, &A2, &M2, &B2, &Y2);
  if (!(Y2 % 4)) y[2]=29;
  }
 
 /*print second date*/
 
  fprintf (stderr, "Second date = %i%c%i%c%i\n", D2 , A2 , M2 , B2 , Y2);
 
 /*convert first date into days*/
 
  for (F = 1; Y1 > F ; F++) 
  {
  if (F % 4 == 0) (Date1 = Date1 + 366);
  else (Date1 = Date1 + 365);
  }
  for (L = 1; M1 > L ; L++) 
  Date1 = Date1 + x[L];
  Date1 = Date1 + D1;
 
 /*convert second date into days*/
 
  for (F = 1; Y2 > F ; F++) 
  {
  if (F % 4 == 0) (Date2 = Date2 + 366);
  else (Date2 = Date2 + 365);
  }
  for (L = 1; M2 > L ; L++) 
  Date2 = Date2 + y[L];
  Date2 = Date2 + D2;
 
 /*standard output*/
 
  Dif = Date2 - Date1;
  printf("\n%i\n\n" , Dif);
 
 /*text output*/
 
  if (Date2 > Date1) 
  {Dif = Date2 - Date1;
  fprintf (stderr , "Indicating that the first date is %i days before second date.\n" , Dif);}
  if (Date1 > Date2) 
  {Dif = Date1 - Date2;
  fprintf (stderr , "Indicating that the second date is %i days before first date.\n" , Dif);} 
  if (Date1 == Date2) 
  fprintf (stderr , "Indicating that the first date is equal to second date.\n"); 
 }

The error appears the system notifies as follows:

date1.c: In function ‘main’:
 date1.c:70:1: warning: control reaches end of non-void function [-Wreturn-type]

I tried to solve it with another sample. I got the reference in the community forum, but it still returned an invalid result. If someone knows the solution, please give me the support. Thanks!

wreturn-type
  • 2 2 Answers
  • 61 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

2 Answers

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    dttutoria Expert
    2022-06-16T23:50:56+00:00Added an answer on June 16, 2022 at 11:50 pm

    The cause: This alert is comparable to the alert mentioned in “Return with no value”. It assumes a return with no return value if control exits a function without encountering a return. The function is supposed to return a value, but you’re not, so the warning occurs.

    Solution: At some point, you must return from the main function like:

      /* .... */
      if (Date1 == Date2)  
         fprintf (stderr , "Indicating that the first date is equal to second date.\n"); 
    
      return 0;
    }

     

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. Emma Charbonnier
    2022-05-25T20:28:56+00:00Added an answer on May 25, 2022 at 8:28 pm

    EXIT_SUCCESS can be used in place of return 0;. EXIT_SUCCESS can also be used instead of return 0;.

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

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • How to Split String by space in C++
  • How To Convert A Pandas DataFrame Column To A List
  • How to Replace Multiple Characters in A String in Python?
  • How To Remove Special Characters From String Python

Explore

  • Home
  • Tutorial

Footer

ITtutoria

ITtutoria

This website is user friendly and will facilitate transferring knowledge. It would be useful for a self-initiated learning process.

@ ITTutoria Co Ltd.

Tutorial

  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA

Legal Stuff

  • About Us
  • Terms of Use
  • Privacy Policy
  • Contact Us

DMCA.com Protection Status

Help

  • Knowledge Base
  • Support

Follow

© 2022 Ittutoria. All Rights Reserved.

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.