[新手]linked list問題
void addList (LIST *list){ //modified from buildList()
//FILE *fpData;
//LIST *list;
short yearIn;
int addResult;
PICTURE *pPic;
//list = createList (cmpYear);
//if (!list)
// printf("\aCannot create list\n" ),
// exit (100);
//fpData = fopen(DATA_FILE_NAME, "r");
//if (!fpData)
// printf("\aError opening input file\n"),
// exit (110);
//while (fscanf(fpData, " %hd", &yearIn) == 1)
//{
if (!(pPic = (PICTURE *)malloc(sizeof(PICTURE))))
printf("\aOut of Memory in build list\n" ),
exit (100);
printf("Enter a four digit year: "); //added
scanf ("%hd", &yearIn); //added
pPic->year = yearIn; //added
/* Skip tabs and quote */
//while ((fgetc(fpData)) != '\t');
//while ((fgetc(fpData)) != '"');
//fscanf(fpData, " %40[^\"], %*c", pPic->picture);
printf("Enter film name: "); //added
fflush(stdin); //added, clear input buffer
scanf ("%[^\n]", pPic->picture); //added, to read string with space until \n is entered
/* Skip tabs and quote */
//while ((fgetc(fpData)) != '\t');
//while ((fgetc(fpData)) != '"');
//fscanf(fpData, " %40[^\"], %*c", pPic->director);
printf("Enter director name: "); //added
fflush(stdin); //added
scanf ("%[^\n]", pPic->director); //added
/* Insert into list */
addResult = addNode (list, pPic);
if (addResult != 0)
{
if (addResult == -1)
printf("Memory overflow adding movie\a\n" ),
exit (120);
else
printf("Duplicate year %hd not added\n\a" ,
pPic->year);
}
//while (fgetc(fpData) != '\n');
//} /* while */
//return list;
}
我是香港的中學生,學了C PROGRAM不夠3個月
我有一個txt檔2000 "Ordinary Heroes" "Ann Hui"
2001 "Crouching Tiger,Hidden Dragon" "Ang Lee"
2002 "Shaolin Soccer" "Stephen Chow"
2003 "Infernal Affairs" "Andrew Lau, Alan Mak"
2004 "Running on Karma" "Johnnie To"
2005 "Kung Fu Hustle" "Stephen Chow"
2006 "Election" "Johnnie To"
2007 "After This Our Exile" "Patrick Tam"
2008 "The Warlords" "Peter Chan"
2009 "Ip Man" "Wilson Yip"
2010 "Bodyguards and Assassins" "Teddy Chan"
2011 "Gallants" "Derek Kwok"
1999 "Beast Cops" "Gordon Chan, Dante Lam"
我在黑色畫面add function,txt檔的文字沒有增加,我是不是code不對???