Still puzzled [I hope this formatted]

This is a discussion on Still puzzled [I hope this formatted] within the C Programming forums, part of the General Programming Boards category; Here is the whole program that I am working on: code _________________________________________________ [#include <stdio.h> #include <string.h> #define NAME_SIZE 26 #define ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    35

    Unhappy Still puzzled [I hope this formatted]

    Here is the whole program that I am working on:

    code
    _________________________________________________
    [#include <stdio.h>
    #include <string.h>
    #define NAME_SIZE 26
    #define ADDRESS_SIZE 26
    #define CITY_STATE_ZIP_SIZE 26
    #define PHONENO_SIZE 16
    void PrintHeadings(void);
    void GetTopLine(void);
    void Calculate(void);
    void CalcInstall(void);
    void CalcSubTotal(void);
    void CalcTotal(void);
    void PrintResults(void);
    void Termination(void);
    void GetTopLine(void);
    void HorizontalLine(void);
    void GetBottomLine(void);
    void lengthWidthArea(char CustomerName[NAME_SIZE], char CustomerAddress[ADDRESS_SIZE],
    char CityStateZip[CITY_STATE_ZIP_SIZE], char CustomerPhoneNo[PHONENO_SIZE], int *length, int *width);
    int PageNo = 1;
    int initialization(char CustomerName[NAME_SIZE], char CustomerAddress[ADDRESS_SIZE],
    char CityStateZip[CITY_STATE_ZIP_SIZE], char CustomerPhoneNo[PHONENO_SIZE], int *length, int *width);
    int processCustomerRecord(char CustomerName[NAME_SIZE], char CustomerAddress[ADDRESS_SIZE],
    char CityStateZip[CITY_STATE_ZIP_SIZE], char CustomerPhoneNo[PHONENO_SIZE], int *length, int *width);
    int calculateLengthWidth( int *length, int *width);
    void termination(void);
    int main(void)
    {
    char CustomerName[NAME_SIZE] = {0};
    char CustomerAddress[ADDRESS_SIZE] = {0};
    char CityStateZip[CITY_STATE_ZIP_SIZE] = {0};
    char CustomerPhoneNo[PHONENO_SIZE] = {0};
    int calculateLengthWidth( int *length, int *width);
    int length;
    int width;

    //int plength = &length;
    int readStatus = 0;

    readStatus = initialization( CustomerName, CustomerAddress,
    CityStateZip, CustomerPhoneNo, &length, &width);
    while ( 6 == readStatus )
    {
    readStatus = processCustomerRecord ( CustomerName, CustomerAddress,
    CityStateZip, CustomerPhoneNo, &length, &width);
    }
    termination();
    return 0;
    }
    // This is where the prime read is
    int initialization(char CustomerName[NAME_SIZE], char CustomerAddress[ADDRESS_SIZE],
    char CityStateZip[CITY_STATE_ZIP_SIZE], char CustomerPhoneNo[PHONENO_SIZE], int *length, int *width)
    {
    int status;
    GetTopLine();
    PrintHeadings();
    status = scanf("%25c %25c %25c %15c %i %i", CustomerName, CustomerAddress, CityStateZip,
    CustomerPhoneNo, length, width);

    return status;
    }
    void GetTopLine(void)
    {
    int tLine = 0;
    printf("%c", 218);
    for(tLine = 0; tLine < 78; tLine++)
    {
    printf("%c", 196);
    }
    printf("%c\n", 191);
    }
    void HorizontalLine(void)
    {
    int hLine = 0;
    for(hLine = 0; hLine < 78; hLine++)
    {
    printf("%c", 196);
    }
    }
    void GetBottomLine(void)
    {
    int bLine = 0;
    printf("%c", 192);
    for(bLine = 0; bLine < 78; bLine++)
    {
    printf("%c", 196);
    }
    printf("%c", 217);
    }
    void PrintHeadings(void)
    {
    int pageNo = 0;
    pageNo++;
    printf("%c", 179);
    printf("Program Name: PA14.exe");
    printf("%15s By Tommy Hicks %10s", "", "");
    printf("Page No %3d", &pageNo);
    printf("%c\n", 179);
    printf("%c", 179);
    printf("Run Date: 08/22/2001 %57s", "");
    printf("%c\n", 179);
    printf("%c", 195);
    HorizontalLine();
    printf("%c\n", 180);

    }

    // This is where the Customer record is written and printed
    int processCustomerRecord(char CustomerName[NAME_SIZE], char CustomerAddress[ADDRESS_SIZE],
    char CityStateZip[CITY_STATE_ZIP_SIZE], char CustomerPhoneNo[PHONENO_SIZE], int *length, int *width)
    {
    int status;
    //int area = 0;//calculateLengthWidth(*length, *width);
    int area = *length * *width;
    char ch;
    printf("%c", 179);
    printf("%25s %51s %c\n", CustomerName, "", 179);
    printf("%c %25s %50s %c\n", 179, CustomerAddress, "", 179);
    printf("%c %25s %50s %c\n", 179, CityStateZip, "", 179);
    printf("%c %15s %60s %c\n", 179, CustomerPhoneNo, "", 179);
    printf("%c", 195);
    HorizontalLine();
    printf("%c\n", 180);
    //status = scanf("%25c %25c %25c %15c %i %i", CustomerName, CustomerAddress, CityStateZip,
    // CustomerPhoneNo, length, width);
    ch = getchar();
    //printf("%c\n", 179);
    printf("%c", 179);
    printf("%37s MEASUREMENT %28s", "", "");
    printf("%c\n", 179);
    printf("%c %76s %c\n", 179, "", 179);
    printf("%c %25s Length %20s %d ft %15s %c\n", 179, "", "", *length, "", 179);
    printf("%c %25s Width %21s %d ft %15s %c\n", 179, "", "", *width, "", 179);
    int area = calculateLengthWidth(*length, *width);
    status = scanf("%25c %25c %25c %15c %i %i", CustomerName, CustomerAddress, CityStateZip,
    CustomerPhoneNo, length, width);
    return status;
    }//End of processCustomerRecord

    int calculateLengthWidth(int *length, int *width)
    (
    int area = *length * *width;
    printf("%c %25s Area %21s %d ft %15s %c\n", 179, "", "", *area, "", 179);
    return area;
    }//end calculateLengthWidth ]

    At this moment I have 15 errors and I know it is because of area.

    I'm not sure if it is how it is declared or how I am calling it.
    Imagination at Work

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    247
    What a lot of code!!!!!!!!!!!!!!!!!!!!!!!!!!!

    One mistake is the call to function, in the calling function you have declared area a couple of times. Declare it once....

    since your original function definition is
    [code]
    int calculateLengthWidth( int *length, int *width);
    /*note the changes below*/

    // This is where the Customer record is written and printed
    int processCustomerRecord(char CustomerName[NAME_SIZE], char CustomerAddress[ADDRESS_SIZE],
    char CityStateZip[CITY_STATE_ZIP_SIZE], char CustomerPhoneNo[PHONENO_SIZE], int *length, int *width)
    {
    int status, area; /*DECLARE area LIKE SO*/

    char ch;
    printf("%c", 179);
    printf("%25s %51s %c\n", CustomerName, "", 179);
    printf("%c %25s %50s %c\n", 179, CustomerAddress, "", 179);
    printf("%c %25s %50s %c\n", 179, CityStateZip, "", 179);
    printf("%c %15s %60s %c\n", 179, CustomerPhoneNo, "", 179);
    printf("%c", 195);
    HorizontalLine();
    printf("%c\n", 180);
    //status = scanf("%25c %25c %25c %15c %i %i", CustomerName, CustomerAddress, CityStateZip,
    // CustomerPhoneNo, length, width);
    ch = getchar();
    //printf("%c\n", 179);
    printf("%c", 179);
    printf("%37s MEASUREMENT %28s", "", "");
    printf("%c\n", 179);
    printf("%c %76s %c\n", 179, "", 179);
    printf("%c %25s Length %20s %d ft %15s %c\n", 179, "", "", *length, "", 179);
    printf("%c %25s Width %21s %d ft %15s %c\n", 179, "", "", *width, "", 179);

    /*THIS IS WHERE YOU ARE INCORRECT - YOUR DECLARATION*/
    /* ABOVE USES POINTERS SO YOU MUST PASS THE ADDRESS*/
    /*OF POINTERS TO THEM WITH "&" OPERATOR */
    area = calculateLengthWidth(&(*length), &(*width));

    status = scanf("%25c %25c %25c %15c %i %i", CustomerName, CustomerAddress, CityStateZip,
    CustomerPhoneNo, length, width);
    return status;
    }//End of processCustomerRecord
    hoping to be certified (programming in c)
    here's the news - I'm officially certified.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    > /*THIS IS WHERE YOU ARE INCORRECT - YOUR DECLARATION*/
    > /* ABOVE USES POINTERS SO YOU MUST PASS THE ADDRESS*/
    > /*OF POINTERS TO THEM WITH "&" OPERATOR */
    > area = calculateLengthWidth(&(*length), &(*width));
    Since length and width are already pointers within this function, the &* you have used here simply cancel one another out, so it's just
    &nbsp; area = calculateLengthWidth( length, width );


    To sketchit
    int calculateLengthWidth(int *length, int *width)
    (
    int area = *length * *width;
    printf("%c %25s Area %21s %d ft %15s %c\n", 179, "", "", *area, "", 179);
    return area;
    }//end calculateLengthWidth ]

    1. The first ( should be a {
    2. Judging from the rest of the code, this function should not be calling printf - all it needs to do is calculate the area and return that value.
    &nbsp; area = calculateLengthWidth( length, width );
    &nbsp; printf("%c %25s Area %21s %d ft %15s %c\n", 179, "", "", area, "", 179);
    happens inside your calling function.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Learned optimism
    By Terrance in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 09-25-2003, 03:06 PM
  2. Bob Hope, dead at 100 of being really old
    By Govtcheez in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 07-28-2003, 08:04 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21