RSS Forums RSS
Please support our C advertiser: Programming Forums
Views: 1026 | Replies: 16 | Thread Tools  Display Modes
Reply
Join Date: Aug 2005
Posts: 4,844
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 325
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: Need help with struct records!

  #11  
Jun 25th, 2008
What are these unsightly things I see,

gets() - ouch
clrscr() - unportable and unnecessary

And if I was being really picky atoi()...
*Voted best profile in the world*
Reply With Quote  
Join Date: Mar 2008
Posts: 10
Reputation: barbiegirl is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
barbiegirl's Avatar
barbiegirl barbiegirl is offline Offline
Newbie Poster

Re: Need help with struct records!

  #12  
Jun 25th, 2008
Originally Posted by jephthah View Post
not really.

how about you NOT talk like a 12-year-old texting message to your friends during recess, mmkay?



.



and how about you shutting the **** up and let me express the way i feel, *******
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
Reply With Quote  
Join Date: Dec 2006
Posts: 232
Reputation: ssharish2005 is on a distinguished road 
Rep Power: 3
Solved Threads: 18
ssharish2005's Avatar
ssharish2005 ssharish2005 is offline Offline
Posting Whiz in Training

Re: Need help with struct records!

  #13  
Jun 25th, 2008
People, can I please request this is not the place to have such a sort of conversation. Comments are accepted but it should be something relevant to OP question. <Kindly>

ssharish
Reply With Quote  
Join Date: Mar 2006
Location: Yorkshire, UK
Posts: 2,921
Reputation: happygeek is on a distinguished road 
Rep Power: 8
Solved Threads: 8
Admin
Staff Writer
Featured Blogger
happygeek's Avatar
happygeek happygeek is offline Offline
He's The Daddy

Re: Need help with struct records!

  #14  
Jun 26th, 2008
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
Reply With Quote  
Join Date: Feb 2008
Posts: 59
Reputation: nelledawg is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
nelledawg nelledawg is offline Offline
Junior Poster in Training

Re: Need help with struct records!

  #15  
Jun 27th, 2008
Originally Posted by jephthah View Post
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 attempt case 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.
Reply With Quote  
Join Date: Apr 2006
Location: NY, USA
Posts: 74
Reputation: death_oclock is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 2
death_oclock's Avatar
death_oclock death_oclock is offline Offline
Junior Poster in Training

Re: Need help with struct records!

  #16  
Jun 27th, 2008
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.
Reply With Quote  
Join Date: Feb 2008
Location: Seattle
Posts: 714
Reputation: jephthah is a jewel in the rough jephthah is a jewel in the rough jephthah is a jewel in the rough 
Rep Power: 4
Solved Threads: 46
jephthah's Avatar
jephthah jephthah is offline Offline
Master Poster

Re: Need help with struct records!

  #17  
Jun 28th, 2008
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.

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5.  
  6. #define COMPANY "Rocklin Realty"
  7. #define TRUE 1
  8. #define FALSE 0 // FORGOT TO DEFINE --jephthah
  9. #define TAB 25
  10.  
  11. void setagents(double *a, int c);
  12. void total_sales(double *m, char **cal, int c);
  13. void agent_sales(double *m, char **cal, int c);
  14. void valid_date(char *date, int min_yr, int max_yr);
  15. void titles(void);
  16. int headings(void);
  17. int menu(void);
  18. void add(void);
  19. int quit(void);
  20. void message(char *msg);
  21. int menuvalid(int min, int max, char item[]);
  22.  
  23.  
  24. char *names[] = {"Larry Lister", "Sue Sales", "Eva Escrow", "Morley Money", "Pete Profit" };
  25.  
  26.  
  27.  
  28. typedef struct
  29. {
  30. int aname; // BEING USED AS AN INT, NOT A CHAR STRING --jephthah
  31. char date[9]; // LENGTH MAY BE TOO SHORT ?? --jephthah
  32. int acode;
  33. double price;
  34. } REALTOR;
  35.  
  36.  
  37. #define clrscr() system("cls")
  38.  
  39. int main()
  40. {
  41.  
  42. int key, more = TRUE;
  43. do
  44. {
  45. key = menu();
  46. switch (key)
  47. {
  48. // COMMENTING OUT UNDEFINED FUNCTIONS -- jephthah
  49. case 1:
  50. //add();
  51. break;
  52. case 2:
  53. //total_sales(m, cal, c);
  54. break;
  55. case 3:
  56. //agent_sales(m, cal, c);
  57. break;
  58. case 4:
  59. more = quit();
  60. break;
  61. default:
  62. message("\nError in selection\a");
  63. }
  64.  
  65. } while (more);
  66.  
  67. return 0;
  68. }
  69. /* ================================================================ */
  70. int menu()
  71. {
  72. int choice;
  73. titles();
  74. printf("1 = Add Records\n", TAB, ' ');
  75. printf("2 = Report Total Sales\n", TAB, ' ');
  76. printf("3 = Report Agent Sales\n", TAB, ' ');
  77. printf("4 = Quit\n", TAB, ' ');
  78.  
  79. choice = menuvalid(1, 4, "choice");
  80. return(choice);
  81. }
  82. /* ================================================================ */
  83. /**/
  84. void add()
  85. {
  86. double agents[6];
  87. double price;
  88. int aname, c, more, items, key;
  89. char choice;
  90. REALTOR s;
  91. FILE *fp;
  92.  
  93.  
  94. fp = fopen("sales.dat", "w+b");
  95. if (fp == NULL)
  96. {
  97. message("Error opening sales.dat\a");
  98. return;
  99. }
  100. fseek(fp, 0L, SEEK_END);
  101. c = (int)ftell(fp) / sizeof(s);
  102.  
  103. // COMMENTING OUT THIS UNDEFINED FUNCTION --jephthah
  104. //setagents(agents,6);
  105.  
  106. do
  107. // YOUVE GOT A FEW PROBLEMS HERE, IVE JUST MADE IT SO IT WILL COMPILE,
  108. // IT WILL NOT NECESSARILY WORK CORRECTLY --jephthah
  109. {
  110. printf("Enter an agent code (1-5): ");
  111. scanf("%d", s.aname); // HAD TOO MANY FORMAT SPECIFIERS --jephthah
  112. printf("Enter sale date for %s: ", names[aname-1]);
  113. fgets(s.date,9,stdin); // NEVER USE 'GETS', USE 'FGETS' --jephthah
  114. printf("Enter the sale price : ");
  115. scanf("%lf", s.price); // HAD TOO MANY FORMAT SPECIFIERS --jephthah
  116. } //FORGOT CLOSING BRACKET --jephthah
  117. while (s.price > 0); // A 'DO' NEEDS A 'WHILE' --jephthah
  118.  
  119. }
  120. /* ================================================================ */
  121. void titles()
  122. {
  123. clrscr();
  124. printf("%*c %s\n\n", TAB, ' ',COMPANY);
  125. } //FORGOT CLOSING BRACKET --jephthah
  126.  
  127. /* ================================================================ */
  128. void message(char *msg)
  129. {
  130. printf("%s, press Enter key to continue\n", msg);
  131. getchar();
  132. }
  133.  
  134. /* ================================================================ */
  135. int quit()
  136. {
  137. char c[5];
  138. int more = TRUE;
  139.  
  140. // 'PROMPT' UNDEFINED.. REPLACING WITH SIMPLE INPUT FUNCTION
  141. // THIS IS *NOT* A VERY ROBUST WAY TO DO IT, JUST ENOUGH TO COMPILE --jephthah
  142.  
  143. //c = prompt("\nTerminate program");
  144.  
  145. printf("\nTerminate Program? (y/n): ");
  146. fgets(c,5,stdin);
  147. if (c[0] == 'Y' || c[0] == 'y')
  148. {
  149. clrscr();
  150. message("\nRocklin Realty Sales Database terminated successfully");
  151. more = FALSE;
  152. }
  153. return more;
  154. }
  155.  
  156. /* ================================================================ */
  157.  
  158.  
  159. // PROBLEM HERE PASSING IN 'DATE' BUT NOT USING IT... RETHINK WHAT
  160. // YOURE ATTEMPTING TO DO WITH THIS FUNTION... GET A DATE FROM USER
  161. // INPUT, AND CHECK IT? OR TAKE AN EXISTING DATE AND CHECK IT? --jephthah
  162. void valid_date(char *date, int min_yr, int max_yr)
  163. {
  164. int mm, dd, yy, max_dd, good;
  165. char msg[80];
  166.  
  167. do
  168. {
  169. printf("Enter the date (mm/dd/yy), press RETURN to quit: ");
  170.  
  171. // WHERE IS 'DATE' COMING FROM? LOCAL OR IS IT PASSED BY CALLER??
  172. // THIS WHOLE FUNCTION WOULD NOT WORK RIGHT IF CALLED --jephthah
  173.  
  174. fgets(date,20,stdin); // NEVER USE 'GETS', USE 'FGETS' --jephthah
  175. if (!date[0])
  176. return;
  177.  
  178. // 'PARSEDATE' FUNCTION NOT DEFINED. CHANGING TO SSCANF --jephthah
  179. good = sscanf(date, "%d/%d/%d",&mm, &dd, &yy);
  180.  
  181. if (!good)
  182. {
  183. message("Date must be in mm/dd/yy format\a");
  184. continue;
  185. }
  186. if (yy < min_yr || yy > max_yr)
  187. {
  188. sprintf(msg, "Year out of range %d to %d\a", min_yr, max_yr);
  189. message(msg);
  190. good = FALSE;
  191. continue;
  192. }
  193. if (mm < 1 || mm > 12)
  194. {
  195. message("Month out of range\a");
  196. good = FALSE;
  197. continue;
  198. }
  199. if (mm==4 || mm==6 || mm==9 || mm==11)
  200. max_dd = 30;
  201. else if (mm==2)
  202. {
  203. // WHERE IS THE 'ISLEAP' MACRO DEFINED? COMMENTING OUT TO COMPILE --jephthah
  204.  
  205. //if (ISLEAP(1900+yy))
  206. max_dd = 29;
  207. //else
  208. // max_dd = 28;
  209. }
  210. else
  211. max_dd = 31;
  212.  
  213. if (dd < 1 || dd > max_dd)
  214. {
  215. message("Day out of range\a");
  216. good = FALSE;
  217. continue;
  218. }
  219. }
  220. while (!good);
  221. }
  222. /* ================================================================ */
  223.  
  224. int menuvalid(int min, int max, char item[])
  225. {
  226. int n;
  227. char buffer[80];
  228.  
  229. printf("Enter the %s %d to %d: ", item, min, max);
  230. fgets(buffer,80,stdin); // NEVER USE 'GETS', USE 'FGETS' --jephthah
  231. n = atoi(buffer);
  232. while (n < min || n > max)
  233. {
  234. message("\nRange Error\a");
  235. printf("Enter the %s %d to %d: ", item, min, max);
  236. fgets(buffer,80,stdin); // NEVER USE 'GETS', USE 'FGETS' --jephthah
  237. n = atoi(buffer);
  238. }
  239. return(n);
  240. }
  241. /* ================================================================ */
Why so serious?
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 11:41 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC