我如何修复下面的代码。我不懂C Langauage。请帮忙 [英] How Do I Fix The Code Below. I Have No Knowledge Of C Langauage. Help Please

查看:71
本文介绍了我如何修复下面的代码。我不懂C Langauage。请帮忙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:格式和预标签



formatting and pre tags

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<dos.h>
#include<ctype.h>
#include<stdlib.h>
#include<graphics.h>
#include<time.h>
#include<bios.h>
#include<dir.h>

/*MACROS ARE DEFINED*/

#define NUM 2
#define PH 11
#define MIN 30
#define MAX 61

void check_id(char *,int);
void check_name(char *,int);
void check_add(char *,int);
void check_phone(char *,int);
int duplicate(char idno[]);

/*FUNCTION DEFINE*/
/*customer fun*/

void cd();
void add();
void view();
void serch();
void del();
void empty();
/*order fun*/
void od();
/*sales fun*/
void sd();
/*song fun*/
void so();
void ho();
void bo();
/*time*/
void t();
void exit();
void append();
void display();
void findData();
void app();
void dispall();
void modify();
void quit();

/*STRUCTURE DEFINE*/

struct customer
{
	char id[NUM];
	char name[MIN];
	char address[MAX];
	char phone[PH];


}rec;
struct record
{
	char cdname[20];
	char director[30];
	float price;

	char publisher[10];
	int qty;

};
struct sales
{
	 char cdcode[20];
	 char cdname[50];
	 long cdprice;
};

int lookup(struct record table[],char s1[],char s2[],int m);
void get(char string[]);


/*======================================================
=		MAIN FUNCTION STRAT		       =
========================================================*/

void main()
{    int c;
	textcolor(RED);
	textbackground(RED+CYAN);
	clrscr();

	do
	{

		t();
		printf("\n\t\t\t\t MR MUSIC SHOP");
		printf("\n\t\t\t\t\t\t\t\t-By MITUL BHATT\n");
		printf("\n\t\t\t\t\t\t\t\t-By RUPESH WAGH\n");
		printf("\n================================================================================");
		printf("\n\n\tCHOICE\t\t\t MAIN MENU\n");
		printf("\n================================================================================");
		printf("\n\n\t 1. \t\t\tCUSTOMER DETAIL\n");
		printf("\n\n\t 2. \t\t\tORDER DETAIL\n");
		printf("\n\n\t 3. \t\t\tSALES REPORT\n");
		printf("\n\n\t 4. \t\t\tSONGS\n");
		printf("\n\n\t 5. \t\t\tEXIT\n");
		printf("\n================================================================================");
		cprintf("\nENTER SELECT YOUR CHOICE...");
		c=(getche());
		switch (c)
		{
			case '1': cd();
			break;   //It will call the cd() funtion to allow user to add and save record.
			case '2': od();
			break;   //It will call the od() funtion to allow user to view the saved record.
			case '3': sd();
			break;   //It will call the sd() funtion to allow user to search records.

			case '4': so();
			break;   //It will call the cal() funtion to allow user to modify name of a saved record.
			case '5': exit(0);
			break;   //It will call the exit() funtion to allow user to modify address of a saved record.
			default:
			puts("\n\n\t\t\t&lt;&lt;--ENTER FROM 1-5 PLEASE--&gt;&gt;\n");	//This message will only print on INVALID ENTRY and Will ask again for input.
			//getch();
		}
	}while(c != '5');
}

/*=======================================================================
=			CUSTOMER DETAILS			        =
=========================================================================*/
void cd()
{
	int c;
	do
	{
		clrscr();
		t();
		printf("\n\t\t\t\t MR MUSIC SHOP");
		printf("\n\t\t\t\t\t\t\t\t-By MITUL BHATT\n");
		printf("\n\t\t\t\t\t\t\t\t-By RUPESH WAGH\n");
		printf("\n================================================================================");
		printf("\n\t\t\t\tCUSTOMER DETAILS\n \t\t\t\t");
		printf("\n================================================================================");
		printf("\n\n\tCHOICE\t\t\t MENU\n");
		printf("\n\n\t [1]\t\t\tADD CUSTOMER\n");
		printf("\n\n\t [2]\t\t\tVIEW CUSTOMER\n");
		printf("\n\n\t [3]\t\t\tSERCH CUSTOMER\n");
		printf("\n\n\t [4]\t\t\tDELETE CUSTOMER\n");
		printf("\n\n\t [5]\t\t\tExit\n");
		printf("\n================================================================================");

		cprintf("\n ENTER SELECT YOUR CHOICE...");


		c=(getche());
		switch (c)
		{
			case '1': add();
			break;   //It will call the add() funtion to allow user to add and save record.
			case '2': view();
			break;   //It will call the view() funtion to allow user to view the saved record.
			case '3':serch();
			break;   //It will call the search() funtion to allow user to search records.
			case '4': del();
			break;   //It will call the delete() funtion to allow user to delete a saved record.

			case '5': exit(0);
			break;   //It will call the c_add() funtion to allow user to modify address of a saved record.
			default:
			puts("&lt;&lt;--ENTER FROM 1-6 PLEASE--&gt;&gt;");	//This message will only print on INVALID ENTRY and Will ask again for input.
			//getch();
		}
	}while(c != '5');
}
void add()
{
	FILE *fp;
	char ch;
	char te[NUM];


	clrscr();


	if(fp!=NULL)
	{
		 do{
		fp=fopen("custome.rec","a");
		clrscr();
		t();
		printf("\n\t\t\t\t MR MUSIC SHOP");
		printf("\n\t\t\t\t\t\t\t\t-By MITUL BHATT\n");
		printf("\n\t\t\t\t\t\t\t\t-By RUPESH WAGH\n");
		printf("\n================================================================================");
		printf("\n\t\t\t\t ADD CUSTOMER RECORD\n \t\t\t\t");
		printf("\n================================================================================");
		printf("\n\n");


			 do{
				   printf("\n ENTER CUSTOMER ID : ");
				   check_id(te, NUM);

			 }while(duplicate(te));
		 strcpy(rec.id, te);
		printf("\n ENTER NAME OF PERSON :");

		check_name(rec.name,MIN);
		printf("\n ENTER ADDRESS       :");
		check_add(rec.address,MAX);
		printf("\n ENTER TELEPHONE NO.        :\t");
		check_phone(rec.phone, PH);


		fwrite(&rec, sizeof(rec), 1, fp);
		fclose(fp);
		printf("\n================================================================================");

		printf("\n\tDo You Want Continue:[Y/N]\n");
		ch=toupper(getche());
	}while(ch=='Y');
     }
	else
	{
	       printf("\n Unable to Open File");
	}
}
void view()
{
	FILE *fp;


	clrscr();
	t();
	fp=fopen("custome.rec","rb");
	if(fp!=NULL)
	{
		clrscr();

		while( fread(&rec, sizeof(rec), 1, fp))
			if(strcmp(rec.id," ")!=0)
			{       clrscr();
				t();
				printf("\n\t\t\t\t MR MUSIC SHOP");
				printf("\n\t\t\t\t\t\t\t\t-By MITUL BHATT\n");
				printf("\n\t\t\t\t\t\t\t\t-By RUPESH WAGH\n");

				printf("\n================================================================================");
				printf("\n\t\t\t\t VIEW CUSTOMER\n \t\t\t\t");
				printf("\n================================================================================");

				printf("\n\tCUSTOMER ID : %s\n",rec.id);

				printf("\n\tCUSTOMER NAME : %s\n",rec.name);

				printf("\n\tCUSTOMER ADDRESS : %s\n",rec.address);

				printf("\n\tTELEPHONE  NUMBER : %s\n",rec.phone);

				printf("\n=================================================================================");

				getch();
			}
	fclose(fp);
	}
	else
	{

		printf("Unable To Open File...");
	}

}

void serch()
{
	int ch;

	FILE *fp;
	char sno[NUM];
	clrscr();

	fp=fopen("custome.rec","rb");
	clrscr();
	t();
	printf("\n\t\t\t\t MR MUSIC SHOP");
	printf("\n\t\t\t\t\t\t\t\t-By MITUL BHATT\n");
	printf("\n\t\t\t\t\t\t\t\t-By RUPESH WAGH\n");
	printf("\n================================================================================");
	printf("\n\t\t\t\tSERCH CUSTOMER RECORD\n\t\t\t\t");
	printf("\n================================================================================");
	printf("\n\n");

	printf("\n\n\t\tPLEASE ENTER CUSTOMER ID ... ");
	check_id(sno,NUM);

		while ( fread(&rec, sizeof(rec), 1, fp) && strcmp(sno,rec.id) );


			ch=strcmp(sno,rec.id);
				if(ch!=0)
				{
					clrscr();
					t();
					printf("\n\t\t\t\t MR MUSIC SHOP");
					printf("\n\t\t\t\t\t\t\t\t-By MITUL BHATT\n");
					printf("\n\t\t\t\t\t\t\t\t-By RUPESH WAGH\n");
					printf("\n================================================================================");
					printf("\n\t\t\t\tSERCH CUSTOMER RECORD\n\t\t\t\t");
					printf("\n================================================================================");
					printf("\n\n");

					sound(500);delay(200);nosound();

					printf("\n\n\n\n\n\n\n\t\t\t&lt;&lt;--RECORD NOT FOUND--&gt;&gt;");
					getch();
				}
				else

				{
					clrscr();

					gotoxy(28,2);
					printf("&lt;&lt;==SEARCH SUCCESSFUL==&gt;&gt;");
					printf("\n\n================================================================================\n");
					gotoxy(3,9);

					printf(" CUSTOMER ID: %s",rec.id);
					gotoxy(3,11);
					printf(" CUSTOMER NAME: %s",rec.name);
					gotoxy(3,13);
					printf(" CUSTOMER ADDRESS: %s",rec.address);
					gotoxy(3,15);
					printf(" CUSTOMER TELEPHONE NUMBER: %s",rec.phone);
					printf("\n=============================================================================");
					gotoxy(3,17);
					cprintf("\n\tPRESS ANY KEY GO TO MAIN MENU :");
					gotoxy(3,21);


					getch();
				}
		fclose(fp);
}

void del()
{

	int ch;
	FILE *fp;
	char cno[NUM];
	clrscr();

	fp=fopen("custome.rec","rb+");
	printf("\n\t\t\t\t MR MUSIC SHOP");
	printf("\n\t\t\t\t\t\t\t\t-By MITUL BHATT\n");
	printf("\n\t\t\t\t\t\t\t\t-By RUPESH WAGH\n");

	printf("\n================================================================================");
	printf("\n\t\t\t\tDELETE CUSTOMER RECORD\n\t\t\t\t");
	printf("\n================================================================================");
	printf("\n\n");
	gotoxy(20,13);
	printf("\n\n\n\n\nPLEASE ENTER CUSTOMER ID :\n ");
	check_id(cno,NUM);

		while ( fread(&rec, sizeof(rec), 1, fp) && strcmp(cno,rec.id) );

			ch=strcmp(cno,rec.id);
				if(ch!=0)
				{
					clrscr();
					t();
					printf("\n\t\t\t\t MR MUSIC SHOP");
					printf("\n\t\t\t\t\t\t\t\t-By MITUL BHATT\n");
					printf("\n\t\t\t\t\t\t\t\t-By RUPESH WAGH\n");

					printf("\n================================================================================");
					printf("\n\t\t\t\tDELETE CUSTOMER RECORD\n\t\t\t\t");
					printf("\n================================================================================");
					printf("\n\n");

					sound(500);delay(200);nosound();

					printf("\n\n\n\n\n\n\n\t\t\t&lt;&lt;--RECORD NOT FOUND--&gt;&gt;");
					getch();
				}
				else     //Here the saved record is displayed.
				{
					clrscr();
					gotoxy(28,2);
					printf("&lt;&lt;==SEARCH SUCCESSFUL==&gt;&gt;");
					gotoxy(3,3);
					printf("\n================================================================================");
					gotoxy(3,5);
					printf(" CUSTOMER ID: %s",rec.id);

					gotoxy(3,7);
					printf(" CUSTOMER NAME: %s",rec.name);

					gotoxy(3,9);
					printf(" CUSTOMER ADDRESS: %s",rec.address);

					gotoxy(3,11);
					printf(" TELEPHONE NUMBER: %s",rec.phone);
					printf("\n================================================================================");

					gotoxy(26,24);
					printf("PRESS ANY KEY TO DELETE RECORD.....");
					getch();
					empty(); //this is a Function which will erase the record in memory & NOT physically.

					fseek(fp, ftell(fp) - sizeof(rec), 0);
					  fwrite(&rec, sizeof(rec), 1, fp);

					clrscr();
					sound(500);delay(200);nosound();
					gotoxy(33,13);
					printf("RECORD DELETED !!!");
					getch();
				}

		fclose(fp);
}

/*========================================================
=	  ORDER DETAILS					 =
==========================================================*/

void od()
{	int c;
	do
	{

		clrscr();
		t();
		printf("\n\t\t\t\t MR MUSIC SHOP");
		printf("\n\t\t\t\t\t\t\t\t-By MITUL BHATT\n");
		printf("\n\t\t\t\t\t\t\t\t-By RUPESH WAGH\n");
		printf("\n================================================================================");
		printf("\n\n\t\t\t\tORDER DETAIL\n");
		printf("\n================================================================================");
		printf("\n\tCHOICE \t\t\tMENU\n");
		printf("\n\n\t 1. \t\t\tAPPEND DATA\n");
		printf("\n\n\t 2. \t\t\tVIEW DATA\n");
		printf("\n\n\t 3. \t\t\tFINDDATA\n");
		printf("\n\n\t 4. \t\t\tEXIT");
		printf("\n================================================================================");
		cprintf("\n ENTER SELECT YOUR CHOICE...");
		c=(getche());
		switch (c)
		{
			case '1': app();
			break;   //It will call the add() funtion to allow user to add and save record.
			case '2': dispall();
			break;   //It will call the view() funtion to allow user to view the saved record.
			case '3': modify();
			break;
			default:
				exit(0);
			break;      //This message will only print on INVALID ENTRY and Will ask again for input.
			//getch();
		}
	}while(c != '3');
}

void app()
{
	  FILE *fp;
	  struct sales obj;
	  clrscr();
	  fp=fopen("data.txt","a");

	  t();
	  printf("\n\t\t\t\t MR MUSIC SHOP");
	  printf("\n\t\t\t\t\t\t\t\t-By MITUL BHATT\n");
	  printf("\n\t\t\t\t\t\t\t\t-By RUPESH WAGH\n");
	  printf("\n================================================================================");
	  printf("\n\tADD RECORD IN THE DATABASE \t\t\t\t");
	  printf("\n================================================================================");

	  printf("\n\n");
	  printf("\nENTER CD CODE  : ");
	  scanf("%s",obj.cdcode);
	  printf("\nENTER CD NAME  : ");
	  scanf("%s",obj.cdname);
	  printf("\nENTER CD PRICE : ");
	  scanf("%ld",&obj.cdprice);
	  fprintf(fp,"%20s %20s %7ld",obj.cdcode,obj.cdname,obj.cdprice);
	  fclose(fp);
}
void dispall()
{
	  FILE *fp;
	  struct sales obj;
	 // char name[20];
	 // char address[50];
	  clrscr();
	  fp=fopen("data.txt","r");

	  t();
	  printf("\n\t\t\t\t MR MUSIC SHOP");
	  printf("\n\t\t\t\t\t\t\t\t-By MITUL BHATT\n");
	  printf("\n\t\t\t\t\t\t\t\t-By RUPESH WAGH\n");
	  printf("\n================================================================================");
	  printf("\n\tDISPLAY ALL RECORD \t\t\t\t");
	  printf("\n================================================================================");

	  printf("\n\n\t\tCODE   \t\t NAME    \t\tPRICE");
	  printf("\n\t\t=======  \t==========  \t\t============\n\n");
	  while(!feof(fp))
	  {
	   fscanf(fp,"%20s %20s %7ld",obj.cdcode,obj.cdname,&obj.cdprice);
	  printf("%20s  %20s %25ld\n",obj.cdcode,obj.cdname,obj.cdprice);
	  }
	  fclose(fp);
	  getch();
}
void modify()
{
	  FILE *fp;
	  struct sales  obj;
	  char cdcode[20];
	  char name[20];
	  char address[50];
	  char cdname[50];
	  int totrec=0;
	  clrscr();
	  fp=fopen("data.txt","r");

	  t();
	  printf("\n\t\t\t\t MR MUSIC SHOP");
	  printf("\n\t\t\t\t\t\t\t\t-By MITUL BHATT\n");
	  printf("\n\t\t\t\t\t\t\t\t-By RUPESH WAGH\n");

	  printf("\n================================================================================");
	  printf("\n\tDISPLAY SPECIFIC RECORD \t\t\t\t");
	  printf("\n================================================================================");

	 printf("\n\n");
	  printf("\nENTER CD CODE : ");
	  scanf("%s",&cdcode);
	  while(!feof(fp))
	  {
	 fscanf(fp,"%20s %20s %7ld",obj.cdcode,obj.cdname,&obj.cdprice);
	     if(strcmpi(obj.cdcode,cdcode)==0)
	     {
		printf("\nCD CODE :  %s",obj.cdcode);
		printf("\nCD NAME  :  %s",obj.cdname);
		printf("\nCD PRICE  : %ld",obj.cdprice);
		totrec++;
	     }
	  }
	  if(totrec==0)
	     printf("\n\n\n\t\t Sorry the record cannot be found in the database.");
	  else
	     printf("\n\n===Total %d Record found===",totrec);
	  fclose(fp);
	  getch();
}
/*void quit()
{
  gotoxy(23,14);
  printf("\tTHANK YOU FOR USING THIS SOFTWARE");
  gotoxy(10,15);
  printf("\tCreated By: Mr. RUPESH WAGH ANDMITUL BHATT MCA SEM-1");
}*/

/*=========================================================
=		SALES DETAILS				  =
===========================================================*/

void sd()
{	int c;
	do
	{
		clrscr();
		printf("\n\t\t\t\t MR MUSIC SHOP");
		printf("\n\t\t\t\t\t\t\t\t-By MITUL BHATT\n");
		printf("\n\t\t\t\t\t\t\t\t-By RUPESH WAGH\n");
		printf("\n================================================================================");
		printf("\n\n\tCHOICE\t\t\t MAIN MENU\n");
		printf("\n================================================================================");
		printf("\n\n\t 1. \t\t\tAPPEND DATA\n");
		printf("\n\n\t 2. \t\t\tVIEW DATA\n");
		printf("\n\n\t 3. \t\t\tFINDDATA\n");
		printf("\n\n\t 4. \t\t\tEXIT");
		printf("\n================================================================================");
		cprintf("\n ENTER SELECT YOUR CHOICE...");
		c=(getche());
		switch (c)
		{
			case '1': append();
			break;   //It will call the add() funtion to allow user to add and save record.
			case '2': display();
			break;   //It will call the view() funtion to allow user to view the saved record.
			case '3': findData();
			break;
			default:
				exit(0);
			break;      //This message will only print on INVALID ENTRY and Will ask again for input.
			//getch();
		}
	}while(c != '3');
}

void append()
{
	  FILE *fp;
	  struct sales obj;
	  clrscr();
	  fp=fopen("data.txt","a");

		t();
		printf("\n\t\t\t\t MR MUSIC SHOP");
		printf("\n\t\t\t\t\t\t\t\t-By MITUL BHATT\n");
		printf("\n\t\t\t\t\t\t\t\t-By RUPESH WAGH\n");

	  printf("\n================================================================================");
	  printf("\n\tADD RECORD IN THE DATABASEE \t\t\t\t");
	  printf("\n================================================================================");


	  printf("\n\n");
	  printf("\nENTER CD CODE  : ");
	  scanf("%s",obj.cdcode);
	  printf("\nENTER CD NAME  : ");
	  scanf("%s",obj.cdname);
	  printf("\nENTER CD PRICE : ");
	  scanf("%ld",&obj.cdprice);
	  fprintf(fp,"%20s %20s %7ld",obj.cdcode,obj.cdname,obj.cdprice);
	  fclose(fp);
}
void display()
{
	  FILE *fp;
	  struct sales obj;
	 // char name[20];
	 // char address[50];
	  clrscr();
	  fp=fopen("data.txt","r");

		t();
		printf("\n\t\t\t\t MR MUSIC SHOP");
		printf("\n\t\t\t\t\t\t\t\t-By MITUL BHATT\n");
		printf("\n\t\t\t\t\t\t\t\t-By RUPESH WAGH\n");
	  printf("\n================================================================================");
	  printf("\n\tDISPLAY ALL RECORD \t\t\t\t");
	  printf("\n================================================================================");


	  printf("\n\n\t\tCODE   \t\t NAME    \t\tPRICE");
	  printf("\n\t\t=======  \t==========  \t\t============\n\n");
	  while(!feof(fp))
	  {
	   fscanf(fp,"%20s %20s %7ld",obj.cdcode,obj.cdname,&obj.cdprice);
	  printf("%20s  %20s %25ld\n",obj.cdcode,obj.cdname,obj.cdprice);
	  }
	  fclose(fp);
	  getch();
}
void findData(){
	  FILE *fp;
	  struct sales  obj;
	  char cdcode[20];
	  char name[20];
	  char address[50];
	  char cdname[50];
	  int totrec=0;
	  clrscr();
	  fp=fopen("data.txt","r");

		t();
		printf("\n\t\t\t\t MR MUSIC SHOP");
		printf("\n\t\t\t\t\t\t\t\t-By MITUL BHATT\n");
		printf("\n\t\t\t\t\t\t\t\t-By RUPESH WAGH\n");

	  printf("\n================================================================================");
	  printf("\n\tDISPLAY SPECIFIC RECORD \t\t\t\t");
	  printf("\n================================================================================");

	  printf("\n\n");
	  printf("\nENTER CD CODE : ");
	  scanf("%s",&cdcode);
	  while(!feof(fp))
	  {
	 fscanf(fp,"%20s %20s %7ld",obj.cdcode,obj.cdname,&obj.cdprice);
	     if(strcmpi(obj.cdcode,cdcode)==0)
	     {
		printf("\nCD CODE :  %s",obj.cdcode);
		printf("\nCD NAME  :  %s",obj.cdname);
		printf("\nCD PRICE  : %ld",obj.cdprice);
		totrec++;
	     }
	  }
	  if(totrec==0)
	     printf("\n\n\n\t\t Sorry the record cannot be found in the database.");
	  else
	     printf("\n\n===Total %d Record found===",totrec);
	  fclose(fp);
	  getch();
}

/*=========================================================
=                 SONGS					  =
===========================================================*/
void so()
{
	int c;
	do
	{
		clrscr();
		t();
		printf("\n\t\t\t\t MR MUSIC SHOP");
		printf("\n\t\t\t\t\t\t\t\t-By MITUL BHATT\n");
		printf("\n\t\t\t\t\t\t\t\t-By RUPESH WAGH\n");
		printf("\n================================================================================");
		printf("\n\t\t\t\tSONGS OPTION\n \t\t\t\t");
		printf("\n================================================================================");
		printf("\n\n\tCHOICE\t\t\t MENU\n");
		printf("\n\n\t [1]\t\t\tHOLLYWOOD\n");
		printf("\n\n\t [2]\t\t\tBOLLYWOOD\n");
		printf("\n\n\t [3]\t\t\tExit\n");
		printf("\n================================================================================");

		cprintf("\n ENTER SELECT YOUR CHOICE...");


		c=(getche());
		switch (c)
		{
			case '1':ho();
			break;   //It will call the add() funtion to allow user to add and save record.
			case '2': bo();
			break;   //It will call the view() funtion to allow user to view the saved record.
			case '3': exit(0);
			break;   //It will call the c_add() funtion to allow user to modify address of a saved record.
			default:
			puts("&lt;&lt;--ENTER FROM 1-3 PLEASE--&gt;&gt;");	//This message will only print on INVALID ENTRY and Will ask again for input.
			//getch();
		}
	}while(c != '3');
}
void bo()
{
	char cdname[30],director[20];
	int index,noofrecord;
	char response[10],qty[10];
	struct record book[]={{"K3G","Yash",20.00,5},{"3Idiots","Raj",100.0,5}};
	noofrecord=sizeof(book)/sizeof(struct record);

	clrscr();

	do
	{

		clrscr();
		t();
		printf("\n\t\t\t\t MR MUSIC SHOP");
		printf("\n\t\t\t\t\t\t\t\t-By MITUL BHATT\n");
		printf("\n\t\t\t\t\t\t\t\t-By RUPESH WAGH\n");
		printf("\n================================================================================");
		printf("\n\t\t\t\tBOLLYWOOD\n \t\t\t\t");
		printf("\n================================================================================");


		printf("ENTER CD NAME AND DIRECTOR IN LIST");
		printf("\n\nCD NAME:    \t\t");
		get(cdname);
		printf("DIRECTOR:     \t\t");
		get(director);
		printf("\n================================================================================");

		index=lookup(book,cdname,director,noofrecord);
		if(index!=-1)
		{
			printf("\n%s%s%.2f%s%d%d\n\n",book[index].director,book[index].cdname,
						     book[index].price,
						     book[index].publisher);

			printf("\nENTER NUMBER OF COPIES::");
			get(qty);
			if(atoi(qty)&gt;book[index].qty)
				printf("COST OF %d COPIES=%.2f\n",atoi(qty),book[index].price*atoi(qty));
			else
				printf("\nREQUIRD COPIS NOT IN STOCK\n");
		}
		else

			printf("THIS CD/DVD IS NOT IN LIST");
		printf("\n================================================================================");
		printf("\nDO U WANT TO ANY OTHER CD/DVD?(y/n):");
		get(response);
	}while(response[0]=='Y' || response[0]=='y');


}


void ho()
{
		char cdname[30],director[20];
		int index,noofrecord;
		char response[10],qty[10];
		struct record book[]={{"transfomers","david",50.00,0},{"avtar","james cameron",100.0,0}};
		noofrecord=sizeof(book)/sizeof(struct record);


       do{
		clrscr();
		t();

		printf("\n\t\t\t\t MR MUSIC SHOP");
		printf("\n\t\t\t\t\t\t\t\t-By MITUL BHATT\n");
		printf("\n\t\t\t\t\t\t\t\t-By RUPESH WAGH\n");
		printf("\n================================================================================");
		printf("\n\t\t\t\tBOLLYWOOD\n \t\t\t\t");
		printf("\n================================================================================");
		printf("ENTER CD NAME AND DIRECTOR NAME AS PER LIST");
		printf("\n\nCD NAME :    \t\t");
		get(cdname);
		printf("DIRECTOR :     \t\t");
		get(director);
		index=lookup(book,cdname,director,noofrecord);
		if(index!=-1)
		{
			printf("\n%s%s%.2f%s%d%d\n\n",book[index].director,book[index].cdname,
						     book[index].price,
						     book[index].publisher);
			printf("\nENTER NUMBER OF COPIES :");
			get(qty);
			if(atoi(qty)&gt;book[index].qty)
				printf("COST OF %d COPIES=%.2f\n",atoi(qty),book[index].price*atoi(qty));
			else
				printf("\nREQIRED COPIS NOT IN STOCK\n");
		}
		else

			printf("THIS CD/DVD NOT IN THE LIST");

		printf("\nDO U WANT TO ANY OTHER CD/DVD?(y/n):");
		get(response);
	}while(response[0]=='Y' || response[0]=='y');


}
void get(char string[])
{
	char c;
	int i=0;
	do
	{
		c=getchar();
		string[i++]=c;
	}
	while(c !='\n');
	string[i-1]='\0';
}

int lookup(struct record table[],char s1[],char s2[],int m)
{
	int i;
	for(i=0;i&lt;m;i++)&gt;
		if(strcmp(s1,table[i].cdname)==0 &&
		strcmp(s2,table[i].director)==0)
		return(i);
	return(-1);
}

/*=================check==============*/

void check_id(char *p, int size)
{
	int i=0;
	char ch;

	do
	{
		ch=getch();

		if( (ch&gt;='0' && ch&lt;='9') && (i&lt;size-1)&gt;		{
			 *p=ch;      	  //The value is assigned to the pointer.
			 p++;        	  //Pointer is incremented.
			 i++;        	  //Length counter is incremented.
			 printf("%c",ch); //Validated character is printed.
		}
		else      //This block of commands controls backspace.
		if(ch==8 && i&gt;0)
		{
			printf("%c%c%c",8,32,8);
			i--;              //Length counter is decremented.
			p--;              //Pointer is decremented.
		}

	}while(ch!=13 || i
	*p='\0';

}


void check_phone(char *ph, int size)
{
	int p=0;
	char s[20],ch;

	do
	{
		ch=getch();

		if( ((ch&gt;='0' && ch&lt;='9')||(ch=='-')) && (p&lt;size-1)&gt;		{
			*ph=ch;
			 ph++;
			 p++;
			 printf("%c",ch);
		}

		else

		if( (ch==8)&&(p&gt;0) )
		{
			printf("%c%c%c",8,32,8);
			p--;
			ph--;
		}

	}while(ch!=13 || p&lt;size-1);&gt;

	s[p]='\0';
	*ph='\0';

}

void check_name(char *p, int size)
{
	int j=0;
	char x[40],cj;

	do
	{

		cj=toupper(getch());

		if(((cj&gt;='a' && cj&lt;='z')||(cj&gt;='A' && cj&lt;='Z')||(cj==' ')) && (j&lt;size-1))&gt;
		{
			*p++=cj;
			j++;
			printf("%c",cj);
		}

		else

		if(cj==8 && j&gt;0)
		{
			printf("%c%c%c",8,32,8);
			j--; p--;
		}

	}while(cj!=13);

	x[j]='\0';
	*p='\0';
}

void check_add(char *p, int size)
{
	int l=0;
	char a[50],ad;

	do
	{

		ad=toupper(getch());

		if(((ad&gt;='a' && ad&lt;='z')||(ad&gt;='A' && ad&lt;='Z')||(ad==' ')||(ad==',')||(ad=='.')||(ad&gt;='0' && ad&lt;='9')) && (l&lt;size-1))&gt;
		{
			*p++=ad;
			l++;
			printf("%c",ad);
		}

		else

		if( (ad==8)&&(l&gt;0) )
		{
			printf("%c%c%c",8,32,8);
			l--; p--;
		}

	}while(ad!=13);

	a[l]='\0';   *p='\0';
}
void t()
{
		int d1, m1, y1 ;
		struct date d;

		getdate(&d);
		d1 = d.da_day ;
		m1 = d.da_mon ;
		y1 = d.da_year ;

		gotoxy(4,4);
		printf("\t\t\t\t\t\t\tDATE:[%d-%d-%d]\n",d1,m1,y1);

}
int duplicate(char idno[])
{
    FILE *fp;

    fp=fopen("custome.rec","rb");

    while(fread(&rec, sizeof(rec), 1, fp) && strcmp(rec.id, idno));
    fclose(fp);

    if(strcmp(rec.id, idno)==0)
       return 1;
    else
       return 0;
}
void empty()
{
     strcpy(rec.id," ");
     strcpy(rec.name," ");
     strcpy(rec.address," ");
     strcpy(rec.phone," ");
}

推荐答案

If you have no knowledge of C, stop fixing code, start learning C and programming. Proceed with smallest possible applications, for exercises, until you achieve good confidence. This is the best advice I can give you. If you don’t want to follow my advice, I must warn you: you will loose a lot of time and will get a lot of frustration.



—SA
If you have no knowledge of C, stop fixing code, start learning C and programming. Proceed with smallest possible applications, for exercises, until you achieve good confidence. This is the best advice I can give you. If you don't want to follow my advice, I must warn you: you will loose a lot of time and will get a lot of frustration.

—SA


这篇关于我如何修复下面的代码。我不懂C Langauage。请帮忙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆