Follow us on twitter

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.


    • CommentAuthorfuryz0r
    • CommentTimeOct 12th 2009 edited
     

    well i have some sort of unknown problem with my c file and h file, they can't compile it, i m using quincy 2005, pls help me take a look.

    This is my C file,
     

    Quote:
    #include <stdlib.h>
    #include <malloc.h>
    #include <string.h>

    #include "key.h"

    key * ky_new(const char * keyCode, int keyId)
    {
    key * ky = (key *) malloc(sizeof(key));
    if(ky != NULL)
    {
    ky->id = keyId;
    ky->code = (char*)malloc(strlen(keyCode));
    if(ky -> code != NULL)
    {

    strcpy(ky->code, keyCode);
    }
    }

    return ky;
    }

    void ky_setCode(key * record, const char * code)
    {
    strcpy(record->code, code);
    }
    char * ky_getCode(key * record)
    {
    return record->code;
    }

    int ky_getId(key * record)
    {
    return record->id;
    }

    key * ky_read(FILE * file)
    {
    int k;
    int id;
    char str[100];

    key * newKey = (key *) malloc(sizeof(key));
    if(file==NULL)
    {
    printf("error opening file!!\n");
    getchar();
    exit(1);
    }
    else
    {
    for(k = 0; k < 10; k++)
    {
    fscanf(file, "%s %s", &(newKey->id), &str);
    }
    newKey->code = (char*)malloc(strlen(str));

    strcpy(newKey->code, str);

    return newKey;
    }
    }

    key * ky_write(FILE * file, key * record)
    {

    fprintf(file, "%d %s\n", record->id, record->code);
    }



    and this is my H file,
     

    Quote:
    #ifndef KEY_H
    #define KEY_H

    #include <stdio.h>

    typedef struct
    {
    int id[100];
    char * code[100];

    }key;

    key * ky_new(const char * keyCode, int keyId);

    void ky_setCode(key * record, const char * code);

    char * ky_getCode(key * record);

    int ky_getId(key * record);

    key * ky_read(FILE * file);

    key * ky_write(FILE * file, key * record);

    #endif




    hopefully someone can help me, thanks a lot.


    • CommentAuthorfuryz0r
    • CommentTimeJan 28th 2010
     
    your Header file is syntactically correct ! but have u kept the header file where the compiler can find ?

Add your comments