im not sure as to why the program is seg faulting when im running it could someone tell me why n how to fix it?
Code:#include "cal.h" /**************************************************************************** * Function main() is the entry point for the program. ****************************************************************************/ int main(void) { unsigned int month; unsigned long year; int MonthIndex; getMonth(&month); getYear(&year); GetDaysofMonth(&month, &year, MonthIndex); return EXIT_SUCCESS; } /**************************************************************************** * Function getMonth() prompt the user for a number MIN_MONTH to MAX_MONTH and * returns that number. The number 0 is valid because this indicates that the * user wants to select all months. ****************************************************************************/ unsigned getMonth(unsigned int *month) { /*** declare variables*/ int i; int flag = 0; int n = 0; char buff [BUFF_SIZE]; int j; printf("Please enter a month between 0 - 12\n"); do { /* input month*/ fgets(buff, BUFF_SIZE, stdin); /** ascii to integer conversion**/ *month = atoi(buff); /* check for bad input*/ while(flag == 1 || *month <0 || *month >12) { flag = 0; printf("**Wrong input Enter month from 0 - 12 only!**\n"); fgets(buff, BUFF_SIZE, stdin); /*cast from ascii to unsigned int*/ *month = atoi(buff); } printf("continue with program!\n"); } while(flag != 0 ); return EXIT_SUCCESS; } /**************************************************************************** * Function getYear() prompts the user for a number MIN_YEAR to MAX_YEAR and GetDaysofMonth(month, year, MonthIndex);* returns that number. ****************************************************************************/ unsigned getYear(unsigned long *year) { return EXIT_SUCCESS; } /****************************** GetDaysofMonth(month, year, MonthIndex);********************************************** * Function displayCalendar() displays the calendar for the user. * The function will display the calendar for a whole month. * If the user supplied a month of "0", then a calendar for a whole year * is displayed instead with each month displayed under the previous one (you * don't need to try to display months side by side). * Give attention to getting the output format exactly as shown below * (including headings and alignment). Here's an example for March 2006: * -------------------- * March 2006int *MonthIndex * S M Tu W Th F S * 1 2 3 4 * 5 6 7 8 9 10 11 * 12 13 14 15 16 17 18 * 19 20 21 22 23 24 25 * 26 27 28 29 30 31 * -------------i------- ****************************************************************************/ void displayCalendar(unsigned int month, unsigned long year) { } /**************************************************************************** * Function readRestOfLine() is used for buffer clearing. Source: * https://inside.cs.rmit.edu.au/~sdb/teaching/C-Prog/CourseDocuments/ * FrequentlyAskedQuestions/ ****************************************************************************/ void readRestOfLine() { int c; /* Read until the end of the line or end-of-file. */ while ((c = fgetc(stdin)) != '\n' && c != EOF) ; /* Clear the error and end-of-file flags. */ clearerr(stdin); } /******************************************************************************* * A function to work out the day of the week for any date using the zella's algorith * * ********************************************************************************/ unsigned GetDaysofMonth(unsigned month, unsigned year, int MonthIndex) { int arr[12]= {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 30}; /* if(year%4==0 && (year%100!=0 || year%400 ==0)) { arr[1] = 29; }*/ return arr[MonthIndex]; }



LinkBack URL
About LinkBacks


