| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 442 人关注过本帖
标题:[新手]linked list問題
只看楼主 加入收藏
gogo3201
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-1-3
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
[新手]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不對???
搜索更多相关主题的帖子: linked create file 
2012-01-03 11:41
lz1091914999
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:四川
等 级:贵宾
威 望:37
帖 子:2011
专家分:5959
注 册:2010-11-1
收藏
得分:20 
程序代码:
int main(void) {
    FILE* out = fopen(DATA_FILE_NAME, "a");
    .......
    .......
    out.printf("%hd\t%s\t%s\n", pPic->year, pPic->picture, pPic->director);
    out.close();
}

My life is brilliant
2012-01-03 12:57
快速回复:[新手]linked list問題
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017331 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved