Thread: pointers

  1. #1
    Unregistered
    Guest

    Unhappy pointers

    I need the program to have a pointer to the Account overdue[13]; I going to use it in the function that have not writen yet. But I try to make a pointer to the Account overdue[13] in main so I can use that data that is store in it in a function. Can you please help me. How do I write a pointer to overdue[13] becouse it hase difrent data types, i just cant sat int *ptr becouse i have int, floats, char in the structure. Basically i needa point for the data in the structure.



    #include <stdio.h>


    typedef struct {
    char Name[21];
    int acct_num;
    float bal;
    float limit;
    }Account;


    int main()
    {

    Account overdue[13];
    int q = 0, n = 1, counter2 = 1 ;
    int AccountNumber = 0 ;
    float Purchase = 0;
    FILE *junk ;

    junk = fopen("d:\\c\\files\\acct9.dat","rb");

    if(junk == NULL)
    fprintf(stderr,"You screw up\n");
    else{

    fread(&overdue[n], sizeof(Account),1,junk);
    while(!feof(junk))
    {

    printf("%s %d %.2f %.2f\n",overdue[n].Name ,overdue[n].acct_num,
    overdue[n].bal, overdue[n].limit);
    n++ ;
    fread(&overdue[n], sizeof(Account),1,junk);
    }



    printf( "Enter Account Number: " );
    scanf( "%d", &AccountNumber );

    /*
    printf( "Enter amount of purchase: " );
    scanf( "%2f", &Purchase ); */

    while ( counter2 <= n )
    {

    if(overdue[counter2].acct_num == AccountNumber)
    {
    printf("Account Found\n\n");
    printf("%s %d %.2f %.2f\n",overdue[counter2].Name ,
    overdue[counter2].acct_num, overdue[counter2].bal,
    overdue[counter2].limit) ;
    break;

    }
    counter2++ ;

    }



    }





    fclose(junk);
    return 0 ;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    The prototype for this function is
    void myfunc ( Account *ptr, int num );

    Within the function,
    &nbsp; ptr[n].limit
    is the same as this in main
    &nbsp; overdue[counter2].limit

    You call it from main like so
    myfunc( overdue, 13 );

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 05:59 AM
  2. Replies: 4
    Last Post: 12-10-2006, 07:08 PM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM