473,406 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Issues with adding/deleting modules and ticker in C

10
I have develop a new coding using C, with some problem where the search and update functions are working but when I enter a record which is not available it getting me to another record, my delete module also is notworking properly, and how to make my time tick. Below is my coding, thankyou for any help.

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<conio.h>
  4. #include<ctype.h>
  5. #include<string.h>
  6. #include <time.h>
  7. void ins(void);
  8. void oldf(void);
  9. void newf(void);
  10. void add(void);
  11. void search(void);
  12. void upd(void);
  13. void del(void);
  14. struct    payroll
  15.     { char no[5];
  16.       char name[25];
  17.       double salary;
  18.       double rate;
  19.       double net;
  20.       } payroll_rec;
  21.  
  22. void main()
  23. {
  24. char i;
  25. time_t now;
  26. time(&now);
  27.  
  28.  
  29. do
  30.   {
  31.     system("cls");
  32.  
  33.     printf("\n\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\7");
  34.     printf("\n\n Welcome to Optimum Technologies' Payroll Department\t\t\t\t\t  %.24s.\n",ctime(&now));
  35.     printf("\t\t   Main Menu\n\n");
  36.     printf("\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\n");
  37.     printf("\nWhat do you wish to do?\n");
  38.     printf("-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n\n");
  39.     printf("1. Insert Employee Record And Compute Weekly Pay\n");
  40.     printf("2. Display All Records\n");
  41.     printf("3. Compute Monthly Pay Slip\n");
  42.     printf("4. Add Employee Record\n");
  43.     printf("5. Search and View Record\n");
  44.     printf("6. Update Record\n");
  45.     printf("7. Delete Record\n");
  46.     printf("8. Exit\n");
  47.     printf("\n-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
  48.     printf("You choose number :");
  49.     i=getche();
  50.  
  51.       switch(tolower(i))
  52.         {
  53.          case '1': ins();  break;
  54.          case '2': oldf();  break;
  55.          case '3': newf();  break;
  56.          case '4': add();  break;
  57.          case '5': search();  break;
  58.          case '6': upd();  break;
  59.          case '7': del();  break;
  60.          case '8': printf("\7\n\tPlease any key to exit...");
  61.                   getch();
  62.                   exit(0);
  63.          break;
  64.          default : printf("\n\tChoice error !  Please try again.");
  65.          getch();
  66.         }
  67.   }while(i!='7');
  68.  
  69. }
  70.  
  71. void ins(void)
  72. {
  73. FILE *fp;
  74. if((fp=fopen("payroll.txt","wb"))==NULL)
  75.    {
  76.     printf("Error in opening file");
  77.      exit(1);
  78.    }
  79. struct payroll
  80. {
  81.   char no[5];
  82.   char name[25];
  83.   double salary;
  84.   double rate;
  85.   double net;
  86.   } payroll_rec;
  87. char numstr[50];
  88.  system("cls");
  89.  printf("\n\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\7");
  90.  printf("\n Insert Employee Record And Compute Weekly Pay Module\n");
  91.  printf("\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3");
  92. do
  93.    {
  94.  
  95.      printf("\n\nEnter Employee No           : ");
  96.      gets(payroll_rec.no);
  97.      printf("Enter Employee Name         : ");
  98.      gets(payroll_rec.name);
  99.     printf("Enter Hours Worked Per Week : ");
  100.      payroll_rec.salary=atof(gets(numstr));
  101.      printf("Enter Hourly Wage           : ");
  102.      payroll_rec.rate=atof(gets(numstr));
  103.      payroll_rec.net=payroll_rec.salary*payroll_rec.rate;
  104.      printf("Your Weekly Pay is RM %.2f\n", payroll_rec.net);
  105.      fwrite(&payroll_rec,sizeof(payroll_rec),1,fp);
  106.      printf("Add another person(y/n)? :");
  107.    }
  108.    while(tolower(getche())=='y');
  109. fclose(fp);
  110. printf("\nPress any key to return to main menu");
  111. getch();
  112. }
  113.  
  114.  
  115. void add(void)
  116. {
  117. FILE *fp;
  118. if((fp=fopen("payroll.txt","ab"))==NULL)
  119.     {
  120.      printf("Error in open file");
  121.      printf("\007");
  122.      getch();  exit(1);
  123.     }
  124. char str[10];
  125.  system("cls");
  126.  printf("\n \5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\7");
  127.  printf("\n\t\t Add Record Module\n ");
  128.  printf("\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\n\n");
  129.   do{
  130.       printf("\nEnter Employee No :");
  131.       gets(payroll_rec.no);
  132.       printf("Enter Employee Name :");
  133.       gets(payroll_rec.name);
  134.       printf("Enter Hours Worked Per Week :");
  135.       payroll_rec.salary=atof(gets(str));
  136.       printf("Enter Hourly Wage:");
  137.       payroll_rec.rate=atof(gets(str));
  138.       payroll_rec.net=payroll_rec.salary*payroll_rec.rate;
  139.       printf("Your Weekly Pay is RM %.2f\n", payroll_rec.net);
  140.       fwrite(&payroll_rec,sizeof(payroll_rec),1,fp);
  141.       printf("Add another person(y/n)? :");
  142.      } while(tolower(getche())=='y');
  143. fclose(fp);
  144.  
  145. }     
  146.  
  147.  
  148. void del(void)
  149. {
  150. FILE*fp;
  151. int i=0;
  152. char ans;
  153. char rec[7];
  154. system("cls");
  155. printf("\n \5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\7");
  156. printf("\n\t\t Delete Record Module\n ");
  157. printf("\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\n\n");
  158. if((fp=fopen("payroll.txt","rb+"))==NULL)
  159. {
  160. printf("Error in open file");
  161. printf("\007");
  162. getch();
  163. exit(1);
  164. }
  165. printf("\n\nThis is data for delete\n");
  166. do{
  167. while(1){
  168. fread(&payroll_rec,sizeof(payroll_rec),1,fp);
  169. if(ferror(fp)){
  170.      printf("\nError read of delete file");
  171.      getch();  exit(1); }
  172.      if(feof(fp))
  173.      break;
  174.      ++i;
  175.      printf("%d. %s\t\t",i,payroll_rec.no);
  176.      }
  177.      printf("\nDo you want to delete data(y or n) :");
  178.      ans=getche();
  179.      if(ans=='y') {
  180.      printf("\nEnter record number :");
  181.      gets(rec);
  182.      fseek(fp,((atoi(rec)-1)*sizeof(payroll_rec)),SEEK_SET);
  183.      strcpy(payroll_rec.no,"\0");
  184.      strcpy(payroll_rec.name,"\0");
  185.      payroll_rec.salary=NULL;
  186.      payroll_rec.rate=NULL;
  187.      payroll_rec.net=NULL;
  188.      fwrite(&payroll_rec,sizeof(payroll_rec),1,fp);
  189.      if(ferror(fp)) {
  190.         printf("Error for delete data\n");
  191.         getch();
  192.         exit(1);
  193.         }
  194.         printf("Delete data complete\n");
  195.         }
  196.         printf("\nContinue(press c) or Exit(press e) :");
  197.         ans=getche();
  198.         printf("\n");
  199.         }while(ans!='e');
  200.         fclose(fp);
  201.         }
Oct 22 '07 #1
2 1194
sicarie
4,677 Expert Mod 4TB
I have develop a new coding using C, with some problem where the search and update functions are working but when I enter a record which is not available it getting me to another record, my delete module also is notworking properly, and how to make my time tick. Below is my coding, thankyou for any help.
Okay, could you rephrase your issue with the add record bit? I'm not following you. Also, you posted a new question, so please use a new thread. Thanks

(You don't have to use a new thread now, as I am going to split this off for you, but in the future when you have a new question and new code please use a new thread. If the question is a continuation of the same code, please stay in the same thread. This is a different enough topic that I am going to pull it out, as I don't believe you're working on code conversion anymore as opposed to just getting the code you have working.)
Oct 22 '07 #2
optimum
10
Sorry for the trouble, still new in the forum.

Actually my question is my coding have problem in its search file module, where when i search for an unavailable file, it keep showing me other file where in my coding i have used "if" function to show error if the search does not found any record. can anybody help me troubleshoot where is the problem. The coding is at the top of the page. Please look for void search();.
And i also would like to know how can i make the time working.

thank you
Oct 23 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: dthelwal | last post by:
I'm looking for an applet or script to feed from an RSS page (perhaps RSS 0.91) and turn its <title> and <link> entries (perhaps using <description> as well) into a scrolling news ticker where the...
3
by: Dan | last post by:
Hi Does anyone know of a good Javascript typewriter ticker that allows you to insert HTML into the ticker. I have found lots but when HTML is inserted, the ticker pauses at the point it reaches...
4
by: Nariak | last post by:
Dear friends of programming! the script below only works with MSI and Opera but not with Netscape 7.x and Mozilla 1.x! What is wrong? Please help me! Thanks Ralf
1
by: Simone | last post by:
Hello. Could you guys please share with me what problems have you faced if any? At work we store all our tables in SQL and use Access as the front end. The access file has many queries...
1
by: David | last post by:
Hi, I have the following asp in my page, but I keep getting the following error Microsoft VBScript runtime error '800a0009' Subscript out of range: 'ticker' Please can you help me ?. Here...
2
by: J_Zanetti | last post by:
Hello everybody! Ive created a ticker that reads my RSS files by loading the xml in an Ajax function. To refresh the content, Ive used a settimeout that reloads the xml, through ajax calls, and...
9
by: Mike | last post by:
I want to create a news/stock/sport ticker for my desktop. I want to have the ability to select my news source, (cnn, msnbc, etcs) sport source(espn, nfl, nba, etc) and my stock source (nasdaq,...
2
by: JoeSox | last post by:
I am importing 3rd party modules via a plugin script. I wish to iterate thru the modules and call a common method like .do_foobar() or something with all the imports. But I can't figure out how to...
13
by: RommelTJ | last post by:
Hi, My website (http://www.justiceinmexico.org/indextest.php) looks good in Firefox, but horrible in IE, and I think it's because of an error in the javascript of a free web ticker I got off the...
0
by: WebCM | last post by:
I hope you can spend some time and help me to select proper application design and programming issues. :) I'm making new version of CMS. I've been mostly theorizing about it for a recent months. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.