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. -
#include<stdio.h>
-
#include<stdlib.h>
-
#include<conio.h>
-
#include<ctype.h>
-
#include<string.h>
-
#include <time.h>
-
void ins(void);
-
void oldf(void);
-
void newf(void);
-
void add(void);
-
void search(void);
-
void upd(void);
-
void del(void);
-
struct payroll
-
{ char no[5];
-
char name[25];
-
double salary;
-
double rate;
-
double net;
-
} payroll_rec;
-
-
void main()
-
{
-
char i;
-
time_t now;
-
time(&now);
-
-
-
do
-
{
-
system("cls");
-
-
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");
-
printf("\n\n Welcome to Optimum Technologies' Payroll Department\t\t\t\t\t %.24s.\n",ctime(&now));
-
printf("\t\t Main Menu\n\n");
-
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");
-
printf("\nWhat do you wish to do?\n");
-
printf("-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n\n");
-
printf("1. Insert Employee Record And Compute Weekly Pay\n");
-
printf("2. Display All Records\n");
-
printf("3. Compute Monthly Pay Slip\n");
-
printf("4. Add Employee Record\n");
-
printf("5. Search and View Record\n");
-
printf("6. Update Record\n");
-
printf("7. Delete Record\n");
-
printf("8. Exit\n");
-
printf("\n-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
-
printf("You choose number :");
-
i=getche();
-
-
switch(tolower(i))
-
{
-
case '1': ins(); break;
-
case '2': oldf(); break;
-
case '3': newf(); break;
-
case '4': add(); break;
-
case '5': search(); break;
-
case '6': upd(); break;
-
case '7': del(); break;
-
case '8': printf("\7\n\tPlease any key to exit...");
-
getch();
-
exit(0);
-
break;
-
default : printf("\n\tChoice error ! Please try again.");
-
getch();
-
}
-
}while(i!='7');
-
-
}
-
-
void ins(void)
-
{
-
FILE *fp;
-
if((fp=fopen("payroll.txt","wb"))==NULL)
-
{
-
printf("Error in opening file");
-
exit(1);
-
}
-
struct payroll
-
{
-
char no[5];
-
char name[25];
-
double salary;
-
double rate;
-
double net;
-
} payroll_rec;
-
char numstr[50];
-
system("cls");
-
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");
-
printf("\n Insert Employee Record And Compute Weekly Pay Module\n");
-
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");
-
do
-
{
-
-
printf("\n\nEnter Employee No : ");
-
gets(payroll_rec.no);
-
printf("Enter Employee Name : ");
-
gets(payroll_rec.name);
-
printf("Enter Hours Worked Per Week : ");
-
payroll_rec.salary=atof(gets(numstr));
-
printf("Enter Hourly Wage : ");
-
payroll_rec.rate=atof(gets(numstr));
-
payroll_rec.net=payroll_rec.salary*payroll_rec.rate;
-
printf("Your Weekly Pay is RM %.2f\n", payroll_rec.net);
-
fwrite(&payroll_rec,sizeof(payroll_rec),1,fp);
-
printf("Add another person(y/n)? :");
-
}
-
while(tolower(getche())=='y');
-
fclose(fp);
-
printf("\nPress any key to return to main menu");
-
getch();
-
}
-
-
-
void add(void)
-
{
-
FILE *fp;
-
if((fp=fopen("payroll.txt","ab"))==NULL)
-
{
-
printf("Error in open file");
-
printf("\007");
-
getch(); exit(1);
-
}
-
char str[10];
-
system("cls");
-
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");
-
printf("\n\t\t Add Record Module\n ");
-
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");
-
do{
-
printf("\nEnter Employee No :");
-
gets(payroll_rec.no);
-
printf("Enter Employee Name :");
-
gets(payroll_rec.name);
-
printf("Enter Hours Worked Per Week :");
-
payroll_rec.salary=atof(gets(str));
-
printf("Enter Hourly Wage:");
-
payroll_rec.rate=atof(gets(str));
-
payroll_rec.net=payroll_rec.salary*payroll_rec.rate;
-
printf("Your Weekly Pay is RM %.2f\n", payroll_rec.net);
-
fwrite(&payroll_rec,sizeof(payroll_rec),1,fp);
-
printf("Add another person(y/n)? :");
-
} while(tolower(getche())=='y');
-
fclose(fp);
-
-
}
-
-
-
void del(void)
-
{
-
FILE*fp;
-
int i=0;
-
char ans;
-
char rec[7];
-
system("cls");
-
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");
-
printf("\n\t\t Delete Record Module\n ");
-
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");
-
if((fp=fopen("payroll.txt","rb+"))==NULL)
-
{
-
printf("Error in open file");
-
printf("\007");
-
getch();
-
exit(1);
-
}
-
printf("\n\nThis is data for delete\n");
-
do{
-
while(1){
-
fread(&payroll_rec,sizeof(payroll_rec),1,fp);
-
if(ferror(fp)){
-
printf("\nError read of delete file");
-
getch(); exit(1); }
-
if(feof(fp))
-
break;
-
++i;
-
printf("%d. %s\t\t",i,payroll_rec.no);
-
}
-
printf("\nDo you want to delete data(y or n) :");
-
ans=getche();
-
if(ans=='y') {
-
printf("\nEnter record number :");
-
gets(rec);
-
fseek(fp,((atoi(rec)-1)*sizeof(payroll_rec)),SEEK_SET);
-
strcpy(payroll_rec.no,"\0");
-
strcpy(payroll_rec.name,"\0");
-
payroll_rec.salary=NULL;
-
payroll_rec.rate=NULL;
-
payroll_rec.net=NULL;
-
fwrite(&payroll_rec,sizeof(payroll_rec),1,fp);
-
if(ferror(fp)) {
-
printf("Error for delete data\n");
-
getch();
-
exit(1);
-
}
-
printf("Delete data complete\n");
-
}
-
printf("\nContinue(press c) or Exit(press e) :");
-
ans=getche();
-
printf("\n");
-
}while(ans!='e');
-
fclose(fp);
-
}
2 1194
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.)
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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.
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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...
|
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,...
| |