I have a header file that I have created. I want to use this header file in a program to spit out data on NFL teams. I seem to be having an issue with my loop under my packers() function. I do not really understand pointers yet so I don't know where I am going wrong with this. Can anyone be of assistance?
First is my header file:
Okay. Now it compiles and runs with the output "The Green Bay Packers" when you select '1'. Why does it work with [2][0][3] entered? And how do I incorporate the other functions of "char superbowl and yearWon"?? I want to have it compile all of that info...
char *nflTeam[4][2][4] =
{ {{"49ers", "Bears", "Bengals", "Bills"}, {"Broncos", "Browns", "Bucaneers", "Cardinals"}}, //data to that shows all team names in
{{"Chargers", "Chiefs", "Colts", "Cowboys"}, {"Dolphins", "Eagles", "Falcons", "Giants"}}, //the NFL
{{"Jaguars", "Jets", "Lions", "Packers"}, {"Panthers", "Patriots", "Raiders", "Rams"}},
{{"Ravens", "Redskins", "Saints", "Seahawks"}, {"Steelers", "Texans", "Titans", "Vikings"}}
};
char *superbowl[4][2][4] =
{ {{"Super Bowls XVI, XIX, XXIII, XXIV & XXIX", "Super Bowl XX", "Im sorry, they lost twice!", "They lost 4 times in a row!!"}, {"Super Bowls XXXII, XXXIII", "Cheer for a different team...", "Super Bowl XXXVII", "They went once...and lost once"}}, //array of data that
{{"Your team sucks. They lost.", "Super Bowl IV", "Super Bowl XLI", "Super Bowls VI, XII, XXVII, XXVIII & XXX"}, {"Super Bowls VII & VIII", "They have gone twice, and lost twice.", "Sorry to burst your bubble, they lost.", "Super Bowls XXI, XXV, XLII and XLVI"}}, //that displays what super bowl
{{"Never been, never will.", "Super Bowl III", "You should cheer for the Packers", "Super Bowls I, II, XXXI and XLV"}, {"Im sorry, they lost once", "Super Bowls XXXVI, XXXVIII, XXXIX and XLIX", "Super Bowls XI & XV", "Super Bowl XXXIV"}}, //the corresponding team has won
{{"Super Bowls V, XXXV & XLVII", "Super Bowls XVII, XXII & XXVI", "Super Bowl XLIV", "Super Bowl XLVIII"}, {"Super Bowls IX, X, XIII, XIV, XL & XLIII", "Time to root for a new team.", "Gone once...and lost", "Gone 4 times, lost EVERY time. You should root for the Packers!"}} //or not won
};
char *yearWon[4][2][4] =
{ {{"1982, 1985, 1989, 1990 & 1995","1986", "1982, 1989", "1991, 1992, 1993 & 1994"}, {"1998 & 1999", "They have never been to a Super Bowl", "2003", "2009"}}, //array of data that shows the year/s
{{"1995", "1970", "2007", "1972, 1978, 1993, 1994 & 1996"}, {"1973 & 1974", "1981 & 2005", "1999", "1987, 1991, 2008 & 2012"}}, //the corresonding team won
{{"um...", "1969", "Never been", "1967, 1968, 1997 & 2011"}, {"2004", "2002, 2004, 2005 & 2015", "1977 & 1981", "2000"}},
{{"1971, 2001 & 2013", "1983, 1988 & 1992", "2010", "2014"}, {"1975, 1976, 1979, 1980, 2006 & 2009", "They have never gone to the big dance!", "2000", "1970, 1974, 1975 & 1977"}}
};
Next is my code:
#include <stdio.h>
#include "nflData.h>
int main(void)
{
int packers(void);
int x=0;
while(1) //while loop to run menu program
{
fprintf(stderr, "\n========MENU========\n\n");
fprintf(stderr, "Choose a team to find out some NFL trivia!: \nEnter 4 to quit.\n"); //prompt user to enter a selection
fprintf(stderr, "1) Packers\n"); //selection options for user
fprintf(stderr, "2) Vikings\n");
fprintf(stderr, "3) Cowboys\n");
fprintf(stderr, "4) Exit\n"); //exits the program
scanf("%d\n", &x); //scanner to read the selection of the user
if(x<1 || x>4)
{
fprintf(stderr, "You entered an invalid entry. Please try again\n"); //denotes that user entered a number that did not
}
else //fall within the selection guidelines
if(x==1)
{
packers(); //call to function packers
}
}
return 0;
}
int packers() //i think the problem is in this function...
{
int i=0;
int j, k;
for(j = 0; j<2; j++){
for(k=0; k<4; k++){
i = *nflTeam[0][j][k];
fprintf(stderr,"The Green Bay %s", nflTeam[2][0][3]);
}
}
return i;
}
printf( "%s\n", nflTeam[2][0][3] );int main( void )int packers( void )