Please support our C advertiser: Programming Forums
![]() |
I'm a Barbie Girl, in a Barbie world, life in plastic, it's fantastic, you can brush my hair, undress me everywhere, Imagination, Life is your creation
•
•
Join Date: Mar 2006
Location: Yorkshire, UK
Posts: 2,921
Reputation:
Rep Power: 8
Solved Threads: 8
Turn the heat down people, or a big moderator flame extinguisher will be switched to max...
Davey Winder
Information Security Journalist of the Year (2008)
www.happygeek.com
Author: Being Virtual
Information Security Journalist of the Year (2008)
www.happygeek.com
Author: Being Virtual
•
•
Join Date: Feb 2008
Posts: 59
Reputation:
Rep Power: 1
Solved Threads: 0
•
•
•
•
nelledogg,
i just gave you postive comment because i thought you wrote that nice code yourself. you said "here is the code i have written"
but then you obviously dont even know how to pass arguments into a simple function, as evidenced by your attemptcase 2: total_sales(double *m, char **cal, int c);
so you DIDNT write any of this code, did you?
because the rest of your code is using far more advanced concepts than passing simple arguments to a function.
now why don't you tell the truth about what's going on here?
Where the hell else would I have gotten this code from? I come on here for help and instead get a bunch of people arguing and some jerk telling me that I didn't write the code just because I'm having problems with it. I'm finishing an assignment from the C Programming class that I got an Incomplete in a year ago, so yeah, I'm having a lot trouble remembering the stuff that I learned, especially considering that I had to take an Incomplete due to very serious medical problems. I wrote this whole code a year ago for a beginning C Programming class, and now I'm just trying to fix the errors and get it to work so I can turn it in and complete the class. Of course I'm not going to be an expert after one semester. If you don't want to help then don't. But I definitely do not need to waste my time reading posts that offer nothing but criticism and arguments.
Last edited by nelledawg : Jun 27th, 2008 at 12:59 am.
Lets please not have everyone get so offended here. Some of you people really need to chill out. In response to the code: When calling a function, you don't include data types. You simply pass in the variables you want the function to use. Although I would recommend doing some reading on pointers as they are a crucial aspect of C. Here's tutorial I really liked as it's very thorough: http://www.iu.hio.no/~mark/CTutorial/CTutorial.html You can skip to the sections on pointers if you wish.
OKAY, Nelledogg,
I apologize for derailing your thread. I'm also sorry for accusing you of not writing the code you posted. It did look kind of odd that you posted all this very nice code with lots of functionality, but there were yet so many compile errors.
i can see, however, that if you had left it for a long time, that you could easily have forgotten what you originally did.
so, lets start over... and get this working for you.
Here is what I have done. I have fixed your code, just enough to make it compile. it does not even come close to doing what you need it to do, there is still a lot of work left that YOU will have to do. but i'll help, and I'm sure many others here will as well.
Inspect what i have done, along with the comments, so you can understand WHY i did what ive done. you'll see that your framework code now compiles and executes with a minimum of functionality.
again, sorry for all the stress.
I apologize for derailing your thread. I'm also sorry for accusing you of not writing the code you posted. It did look kind of odd that you posted all this very nice code with lots of functionality, but there were yet so many compile errors.
i can see, however, that if you had left it for a long time, that you could easily have forgotten what you originally did.
so, lets start over... and get this working for you.
Here is what I have done. I have fixed your code, just enough to make it compile. it does not even come close to doing what you need it to do, there is still a lot of work left that YOU will have to do. but i'll help, and I'm sure many others here will as well.
Inspect what i have done, along with the comments, so you can understand WHY i did what ive done. you'll see that your framework code now compiles and executes with a minimum of functionality.
again, sorry for all the stress.
c Syntax (Toggle Plain Text)
#include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #define COMPANY "Rocklin Realty" #define TRUE 1 #define FALSE 0 // FORGOT TO DEFINE --jephthah #define TAB 25 void setagents(double *a, int c); void total_sales(double *m, char **cal, int c); void agent_sales(double *m, char **cal, int c); void valid_date(char *date, int min_yr, int max_yr); void titles(void); int headings(void); int menu(void); void add(void); int quit(void); void message(char *msg); int menuvalid(int min, int max, char item[]); char *names[] = {"Larry Lister", "Sue Sales", "Eva Escrow", "Morley Money", "Pete Profit" }; typedef struct { int aname; // BEING USED AS AN INT, NOT A CHAR STRING --jephthah char date[9]; // LENGTH MAY BE TOO SHORT ?? --jephthah int acode; double price; } REALTOR; #define clrscr() system("cls") int main() { int key, more = TRUE; do { key = menu(); switch (key) { // COMMENTING OUT UNDEFINED FUNCTIONS -- jephthah case 1: //add(); break; case 2: //total_sales(m, cal, c); break; case 3: //agent_sales(m, cal, c); break; case 4: more = quit(); break; default: message("\nError in selection\a"); } } while (more); return 0; } /* ================================================================ */ int menu() { int choice; titles(); printf("1 = Add Records\n", TAB, ' '); printf("2 = Report Total Sales\n", TAB, ' '); printf("3 = Report Agent Sales\n", TAB, ' '); printf("4 = Quit\n", TAB, ' '); choice = menuvalid(1, 4, "choice"); return(choice); } /* ================================================================ */ /**/ void add() { double agents[6]; double price; int aname, c, more, items, key; char choice; REALTOR s; FILE *fp; fp = fopen("sales.dat", "w+b"); if (fp == NULL) { message("Error opening sales.dat\a"); return; } fseek(fp, 0L, SEEK_END); c = (int)ftell(fp) / sizeof(s); // COMMENTING OUT THIS UNDEFINED FUNCTION --jephthah //setagents(agents,6); do // YOUVE GOT A FEW PROBLEMS HERE, IVE JUST MADE IT SO IT WILL COMPILE, // IT WILL NOT NECESSARILY WORK CORRECTLY --jephthah { printf("Enter an agent code (1-5): "); scanf("%d", s.aname); // HAD TOO MANY FORMAT SPECIFIERS --jephthah printf("Enter sale date for %s: ", names[aname-1]); fgets(s.date,9,stdin); // NEVER USE 'GETS', USE 'FGETS' --jephthah printf("Enter the sale price : "); scanf("%lf", s.price); // HAD TOO MANY FORMAT SPECIFIERS --jephthah } //FORGOT CLOSING BRACKET --jephthah while (s.price > 0); // A 'DO' NEEDS A 'WHILE' --jephthah } /* ================================================================ */ void titles() { clrscr(); printf("%*c %s\n\n", TAB, ' ',COMPANY); } //FORGOT CLOSING BRACKET --jephthah /* ================================================================ */ void message(char *msg) { printf("%s, press Enter key to continue\n", msg); getchar(); } /* ================================================================ */ int quit() { char c[5]; int more = TRUE; // 'PROMPT' UNDEFINED.. REPLACING WITH SIMPLE INPUT FUNCTION // THIS IS *NOT* A VERY ROBUST WAY TO DO IT, JUST ENOUGH TO COMPILE --jephthah //c = prompt("\nTerminate program"); printf("\nTerminate Program? (y/n): "); fgets(c,5,stdin); if (c[0] == 'Y' || c[0] == 'y') { clrscr(); message("\nRocklin Realty Sales Database terminated successfully"); more = FALSE; } return more; } /* ================================================================ */ // PROBLEM HERE PASSING IN 'DATE' BUT NOT USING IT... RETHINK WHAT // YOURE ATTEMPTING TO DO WITH THIS FUNTION... GET A DATE FROM USER // INPUT, AND CHECK IT? OR TAKE AN EXISTING DATE AND CHECK IT? --jephthah void valid_date(char *date, int min_yr, int max_yr) { int mm, dd, yy, max_dd, good; char msg[80]; do { printf("Enter the date (mm/dd/yy), press RETURN to quit: "); // WHERE IS 'DATE' COMING FROM? LOCAL OR IS IT PASSED BY CALLER?? // THIS WHOLE FUNCTION WOULD NOT WORK RIGHT IF CALLED --jephthah fgets(date,20,stdin); // NEVER USE 'GETS', USE 'FGETS' --jephthah if (!date[0]) return; // 'PARSEDATE' FUNCTION NOT DEFINED. CHANGING TO SSCANF --jephthah good = sscanf(date, "%d/%d/%d",&mm, &dd, &yy); if (!good) { message("Date must be in mm/dd/yy format\a"); continue; } if (yy < min_yr || yy > max_yr) { sprintf(msg, "Year out of range %d to %d\a", min_yr, max_yr); message(msg); good = FALSE; continue; } if (mm < 1 || mm > 12) { message("Month out of range\a"); good = FALSE; continue; } if (mm==4 || mm==6 || mm==9 || mm==11) max_dd = 30; else if (mm==2) { // WHERE IS THE 'ISLEAP' MACRO DEFINED? COMMENTING OUT TO COMPILE --jephthah //if (ISLEAP(1900+yy)) max_dd = 29; //else // max_dd = 28; } else max_dd = 31; if (dd < 1 || dd > max_dd) { message("Day out of range\a"); good = FALSE; continue; } } while (!good); } /* ================================================================ */ int menuvalid(int min, int max, char item[]) { int n; char buffer[80]; printf("Enter the %s %d to %d: ", item, min, max); fgets(buffer,80,stdin); // NEVER USE 'GETS', USE 'FGETS' --jephthah n = atoi(buffer); while (n < min || n > max) { message("\nRange Error\a"); printf("Enter the %s %d to %d: ", item, min, max); fgets(buffer,80,stdin); // NEVER USE 'GETS', USE 'FGETS' --jephthah n = atoi(buffer); } return(n); } /* ================================================================ */
Why so serious?
![]() |
Similar Threads
Other Threads in the C Forum
- Declaring an array of records in MC++ (C++)
- stuck in Menu loop!! (C)
- Array Struct Sort Help!! Urgent! (C)
- array struct display?? (C)
- Data stored in Records (C#)
- Trouble Reading Records (C++)
- reading records from a file (C++)
- fstream and struct question (C++)
Other Threads in the C Forum
- Previous Thread: How to create an MP3 player.
- Next Thread: Reversing doubly linked list?
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode