Thread: calling computeach students

  1. #1
    Unregistered
    Guest

    Angry calling computeach students

    re 425 project program 5

    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
    #include <ctype.h>
    #include <stdlib.h>
    #include <time.h>
    #include <isam.h>
    #include <common.h>




    FILE *fp_stock_master;
    FILE *fp_out;

    int x=1;


    RECORD_DATA *stock_rec;

    int main()
    {


    if((fp_stock_master=fopen("A:STCKMAST.DAT","rb"))= =NULL)
    {
    printf("ERROR OPENING STOCK MASTER FILE\n");
    exit(1);
    }
    else
    printf("OPENING STOCK MASTER FILE\n");



    while (x==1 )
    {
    if(fread(stock_rec,sizeof(RECORD_DATA),1,fp_stock_ master)!=1)
    {
    if(feof(fp_stock_master))
    { printf("end of file");x=0;strcpy(stock_rec->desc,"\0");break;}
    else if(!feof(fp_stock_master)) /*else reading error*/
    {printf("\nERROR READING CUSTOMER MASTER FILE - PROGRAM TERMINATED");exit(1); }
    }

    if(x==1)

    printf("%6s %19s %02d %06ld %04d %06s %06.2f\n",stock_rec->key,stock_rec->desc,
    stock_rec->supp_code,stock_rec->free_stock,stock_rec->min_stock,
    stock_rec->movement_date,stock_rec->price);

    }

    fclose(fp_stock_master);
    return 1;
    }

    this is trying to read my master file and it just gives a value of null for the stock_rec->key

    i cant get a value for the part number at all and am having real problems with this program.

    can anyone help

    steve

  2. #2
    Unregistered
    Guest
    'stock_rec' pointer is not initialized.

    allocate memory for one RECORD_DATA variable and assign the pointer to it's addres

  3. #3
    Unregistered
    Guest
    i'm not sure what you mean really,
    the record data structure is defined in a header as -

    typedef struct
    {
    char key[7];
    char desc[20];
    short supp_code;
    long free_stock;
    short min_stock;
    char movement_date[7];
    float price;
    } RECORD_DATA;

    so when i run my prog, it reads all the data correctly, but gives a value of null for the key, i don't understand at all !!!!!!!

  4. #4
    Registered User breed's Avatar
    Join Date
    Oct 2001
    Posts
    91
    I'm a newbie myself so it might not be a good idea in taking this advice.
    but i thought i might attempt it cos I'm on the compy course aswell.
    Looking at you code the only thing i can see is the fread ()
    maybe you should try and use the at the address operator

    if(fread(&stock_rec,sizeof(RECORD_DATA),1,fp_stock _
    master)!=1)

    if it dose'nt work sos // if it does cool!
    Before you judge a man, walk a mile in his
    shoes. After that, who cares.. He's a mile away and you've got
    his shoes.
    ************William Connoly

  5. #5
    Registered User breed's Avatar
    Join Date
    Oct 2001
    Posts
    91
    I'm a newbie myself so it might not be a good idea in taking this advice.
    but i thought i might attempt it cos I'm on the compy course aswell.
    Looking at you code the only thing i can see is the fread ()
    maybe you should try and use the at the address operator

    if(fread(&stock_rec,sizeof(RECORD_DATA),1,fp_stock _
    master)!=1)

    if it dose'nt work sos // if it does cool!
    Before you judge a man, walk a mile in his
    shoes. After that, who cares.. He's a mile away and you've got
    his shoes.
    ************William Connoly

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    247

    the more the merrier

    Hey, welcome to all, we are not alone!!!

    maybe the webmaster should think on setting up a "compubunglers" forum, so we could all gripe together lol.

    or set up an e-mail group.

    Code:
    char name[MAX];
    int computeach_students = 0;
    
    puts("If computeach student - Enter name");
    gets(name);
    computeach_student++;
    
    puts("Happy with there service")
    if((toupper(getch())) == 'N')
       computeach_student--;
    hoping to be certified (programming in c)
    here's the news - I'm officially certified.

  7. #7
    Unregistered
    Guest
    "Hey, welcome to all, we are not alone!!!

    maybe the webmaster should think on setting up a "compubunglers" forum, so we could all gripe together lol.

    or set up an e-mail group. "


    Hey, try www.computeachstudents.ukf.net

  8. #8
    My diaper's full....... stevey's Avatar
    Join Date
    Nov 2001
    Posts
    746
    all problems solved on the why does it crash thread, thanx

    i shouldn't have started a new thread really

    hey dont try with the "&" that crashes the OS !!!!!!!!!!!!!!

    good look to all COMPY people , we need it !!!!!!!!!!!!!1

    steve
    Steve

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C program using structs to calculate grades
    By TampaTrinDM88 in forum C Programming
    Replies: 4
    Last Post: 07-06-2009, 12:33 PM
  2. Stack issues when calling a COM library
    By notnot in forum C Programming
    Replies: 3
    Last Post: 06-01-2009, 02:12 AM
  3. realloc segfaults.
    By noobcpp in forum C Programming
    Replies: 24
    Last Post: 11-26-2008, 01:16 AM
  4. new problem with class
    By jrb47 in forum C++ Programming
    Replies: 0
    Last Post: 12-01-2006, 08:39 AM
  5. Any Computeach International Students/ex students??
    By stevey in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 03-26-2002, 04:12 PM