ºìÁªLinuxÃÅ»§
Linux°ïÖú

ÔõôÓÃlinuxÀïµÄmakeÃüÁî±àÒ룿

·¢²¼Ê±¼ä:2008-12-02 16:14:41À´Ô´:ºìÁª×÷Õß:NIDHOGOO
ÕâÊÇÒ»¸öСÉÌÆ·¹ÜÀíϵͳµÄ´úÂ룬ÏëÓÃlinuxµÄmakeÃüÁîÀ´±àÒëµ÷ÊÔ£¬µ«ÊDz»ÖªµÀÕâ¸ömakefileÎļþÔõô×ö£¬Çë½Ì¸ßÊÖÖ¸½Ì¡£´úÂëÈçÏ£º
ÕâÊǹ˿͵ǽģ¿é
Ô´Îļþ£ºlogin.c
Í·Îļþ£ºuser.h

login.c
/*login.c: ¹Ë¿ÍµÇ¼£¬ÅжϹ˿͵ǼÃû¡¢ÃÜÂëºÍȨÏÞ£¬
¸ù¾ÝȨÏÞµ÷ÓÃÏàÓ¦¹¦ÄÜÑ¡Ôñ½çÃæ*/
/*°üº¬¹Ë¿ÍÐÅϢͷÎļþ
°üº¬´´½¨¹Ë¿ÍÐÅÏ¢¡¢Ôö¼Ó¡¢É¾³ý¡¢Ð޸ġ¢ÅÅÐòµÄ¹Ë¿Í´¦Àí³ÌÐò
°üº¬¹ÜÀíÔ±¡¢ÆÕͨ¹Ë¿ÍµÄ¹¦ÄÜÑ¡Ôñ½çÃæ´¦Àí³ÌÐò*/
#include "user.h"
#include "cuser.c"
#include "admin.c"
#include "guest.c"
#include "adduser.c"
#include "deluser.c"
#include "sunum.c"
#include "munum.c"
int main( )
{
FILE *fp = NULL;
user Show;
user Tmps; /*ÁÙʱ´æ·Å¹Ë¿ÍÐÅÏ¢µÄ½á¹¹Ìå±äÁ¿*/
char DataFile[40] = "yonghu"; /*´æ·Å¹Ë¿ÍÐÅÏ¢µÄÎļþÃûΪyonghu*/
int i;
char relogin; /*ÊÇ·ñÖØеǼµÄ±êÖ¾*/
int success=0; /*µÇ½³É¹¦µÄ±êÖ¾*/
/*CreatUser( );*/
printf("#===========================================#\n");
printf("# Welcome to the Product Management System! #\n");
printf("============================================#\n");
again:
/*ÊäÈëµÇ¼Ãû*/
printf("please enter the user name:");
scanf("%s",Tmps.Name);



/*ÊäÈëÃÜÂ룬Óò»´ø»ØÏԵķ½Ê½±£Ö¤°²È«ÐÔ*/
printf("password=");
for(i=0;i<6;i++)
{
Tmps.ps[i]=gatch( );
}


Tmps.ps[6]='\0';
/*´ò¿ªyonghuÎļþ£¬ÓÃÀ´ÑéÖ¤µÇ¼ÃûºÍÃÜÂë*/
fp=fopen(DataFile,"rb");
if (fp == NULL)
{
printf("\nOpen file%sfail!End with any key \n",DataFile);
perror("\OPen file fail");
getch( );
exit(1);
}
/*Ñ­»·¶ÁÈ¡ÎļþУÑéµÇ¼ÃûºÍÃÜÂëÊÇ·ñÕýÈ·*/
while(fread(&Show,sizeof(user),1,fp) != (int)NULL)
(
/*Èç¹ûͨ¹ýÑéÖ¤£¬Ôò½«success³É¹¦µÇ¼±ê¼ÇÉèΪ1*/
if((strcmp (Tmps.Name,Show.Name)==0)&&(strcmp(Tmps.ps,Show.ps)==0))
{
printf("\nlogin successful!\n");
success=1;
/*ÅжÏȨÏÞ£¬ÈçpowerµÄֵΪ1£¬ÔòÊǹÜÀíÔ±£¬²¢µ÷ÓùÜÀíÔ±¹¦ÄÜÑ¡Ôñ½çÃæ*/
if(Show.power==1)
{
printf("\nyour power is administrator!\n");
admin( );/*µ÷ÓùÜÀíԱϵͳÖ÷¿Øƽ̨*/
)
/*ÅжÏȨÏÞ£¬ÈçpowerµÄֵΪ0£¬ÔòÊÇÆÕͨ¹Ë¿Í£¬²¢µ÷ÓÃÆÕͨ¹Ë¿Í¹¦ÄÜÑ¡Ôñ½çÃæ*/
if(Show.power==0)
{
printf("\nyour power is user!\n");
Guest( );/*µ÷ÓÃÆÕͨÓû§ÏµÍ³Ö÷¿Øƽ̨*/
}
}
}
/*ÈçδÄܳɹ¦µÇ¼£¬Èù˿ÍÑ¡ÔñÖØеǼ»òÍƳö*/
if(success==0)
{
getchar( );
printf("\nerror user name or password!input again?(y/n)");
scanf("%c",&relogin);
if((relogin=='Y')!!(relogin=='y'))
{
printf("you choose input again:\n");
goto again;)
else
{
printf("end program");
getch( );
exit(0);
}
}
}


user.h
/*===================user.h========================================*/
#include "stdio.h"
#include
#include
#include
#define SIZE 100
typedef struct
{
long Number; /*¹Ë¿ÍÐòºÅ*/
char Name[20]; /*¹Ë¿ÍÃû³Æ*/
char ps[8]; /*¹Ë¿ÍÃÜÂë*/
int power; /*¹Ë¿ÍȨÏÞ*/
}user;
extern void Guest( ); /*ÆÕͨ¿Í»§¹¦ÄÜÑ¡Ôñ½çÃæ*/
extern void Admin( ); /*¹ÜÀíÔ±¹¦ÄÜÑ¡Ôñ½çÃæ */
extern void CreatUser( ); /*´´½¨¿Í»§ÐÅÏ¢Îļþ */
extern void AddUser( ); /*Ôö¼Ó¹Ë¿Í¼Ç¼ */
extern void DelUser( ); /*ɾ³ý¿Í»§¼Ç¼ */
extern void ModifyByUserNumber( ); /*¸ù¾Ý¹Ë¿ÍÐòºÅÐÞ¸Ä */
extern void SortByUserNum( ); /*¸ù¾Ý¹Ë¿ÍÐòºÅÅÅÐòä¯ÀÀ*/

Õâ¸öÊÇÉÌÆ·ÐÅÏ¢¹ÜÀíÄ£¿éµÄ´úÂë
³ÌÐòÇåµ¥£¨1£©£ºshead.h
#include "stdio.h"
#include "stdio.h"
#include
#include
#include
#define SIZE 100 /* mac.ros definition*/
typedef struct
{
long Number; /*Field of number */
char Name[20]; /*Field of name */
float price; /*Field of price */
float discount; /*Field of discount */
float memberprice; /*Field of memberprice */
}product;
extern void CreatFile( ); /*´´½¨ÐÅÏ¢Îļþ*/
extern void AddRecord( ); /*Ôö¼Ó */
extern void DelRecord( ); /*ɾ³ý */
extern void ModifyByNumber( ); /*ÐÞ¸Ä */
extern void QueryBySeatNum( ); /*°´ÐòºÅ²éѯ */
extern void QueryByName( ); /*°´ÐÕÃû²éѯ */
extern void SortByMemberprice( ); /*°´ºÏ¼Æ²éѯ */

³ÌÐòÇåµ¥£¨2£©£ºadmin.c
/*admin.c:¹ÜÀíÔ±¹¦ÄÜÑ¡Ôñ½çÃ棬¸ù¾Ý¿Í»§Ñ¡Ïîµ÷ÓÃÏàÓ¦º¯ÊýʵÏÖϵͳ¹¦ÄÜ*/
#include "shead.h"
#include "creat.c"
#include "add.c"
#include "delete.c"
#include "modnum.c"
#include "qname.c"
#include "qseatnum.c"
#include "smprice.c"
void Admin( )
{
int choice = 0;/*´æ·Å¿Í»§Ñ¡ÏîµÄ±äÁ¿*/
/*====¹¦Äܼ°²Ù×÷µÄ½çÃæÌáʾ====*/
while(1)
{
printf("--------------------------------------------------------------------------------------\n");
printf("| |\n");
printf("| Welcome to Product Management System |\n");
printf("| |\n");
printf("|-------------------------------------------------------------------------------------|\n");
printf ("| 1. Init Product Information File |\n");
printf("| 2. AddProduct( ) |\n");
printf("| 3. DelProdut( ) |\n");
printf("| 4. QueryByProductName( ) |\n");
printf("| 5. QueryByProductNum( ) |\n");
printf("| 6. ModifyByProductNumber( ) |\n");
printf("| 7. SortByMemberPrice( ) |\n");
printf("+++++++++++++++++++++++++++++++++++++++++++++++++++\n");
printf("| System User Management |\n");
printf("| 11. CreatNewUserFile( ) |\n");
printf("| 12. AddUser( ) |\n");
printf("| 13. DelUser( ) |\n");
printf("| 14. ModifyUser( ) |\n");
printf("| 15. SortByUserNum( ) |\n");
printf("+++++++++++++++++++++++++++++++++++++++++++++++++++\n");
printf("| 0. Exit System |\n");
printf("----------------------------------------------------------------------------------------\n");
printf("# Please Input Your Choose #\n");
printf("# number 1~7 to Mange the Product Information #\n");
printf("# number 11,12,13,14,15 to Mange the System User #\n");
printf("# number 0 to Exit the System #\n");
printf("-----------------------------------------------------------------------------------------\n");
scanf("%d",&choice);
getchar( );
/*¸ù¾Ý¿Í»§Ñ¡Ïîµ÷ÓÃÏàÓ¦º¯Êý*/
switch(choice)
{
case 1:
CreatFile( );
break;
case 2:
AddRecord( );
break;
case 3:
DelRecord( );
break;
case 4:
QueryByName( );
break;
case 5:
QueryBySeatNum( );
break;
case 6:
ModifyByNumber( );
break;
case 7:
SortByMemberPrice( );
break;
case 11:
CreatUser( );
break;
case 12:
AddUser( );
break;
case 13:
DelUser( );
break;
case 14:
ModifyByUserNumber( );
break;
case 15:
SortByUserNum( );
break;


case 0:
exit(0);
default:
break;
}
}
}
³ÌÐòÇåµ¥£¨3£©£ºcreat.c
/*creat.c:ÓÃÓÚ´´½¨ÉÌÆ·ÐÅÏ¢Îļþ*/
#include "stdio.h"
/*º¯ÊýCreatFile*/
void CreatFile( )
{
FILE *fp = NULL; /*¶¨ÒåÖ¸ÏòÎļþµÄÖ¸Õë*/
product Tmps; /*¶¨Òå½øÐвÙ×÷ʱ´æ·Å½á¹¹Ìå±äÁ¿µÄ*/
char DataFile[40] = ""; /*´æ´¢ÉÌÆ·ÐÅÏ¢µÄÎļþÃû*/
int count = 1; /*¼ÆËã¿ÉÊäÈëÊý¾ÝµÄ×î´ó·¶Î§*/
/*====ÊäÈë´æ·ÅÉÌÆ·ÐÅÏ¢µÄÎļþÃû====*/
printf("\n please input new file name of product information.");
printf("\n Notice:Name of file can't exceed 8 characters.suffix can't
exceed 3 characters,part of exceed will be discarded.\n");
gets(DataFile);
/*Èç¹Ë¿ÍûÓÐÊäÈ룬ÔòÑ­»·Ìáʾ¹Ë¿ÍÊäÈë*/
while(*DataFile == ('\0'))
{
printf("\n please input new file name to store data,end with enter.");
printf("\n Notice:Name of file can't exceed 8 characters,suffix can't
exceed 3 characters.part of exceed will be discarded.\n");
gets(DataFile);
}
/*Óöþ½øÖÆдµÄ·½Ê½´ò¿ªÎļþ£¬¼´´´½¨Îļþ*/
fp = fopen(DataFile,"wb+");
/*Èç¹ûµ±Ç°Îļþ²»´æÔÚ£¬Ìáʾ´ò¿ªÎļþʧ°Ü*/
if (fp == NULL)
{
printf("\n Open file %s fail!End with any key.\n",DataFile);
printf("Open file fail");


gatch( );
exit(1);
}
/*Èç¹û³É¹¦´ò¿ª»ò´´½¨Îļþ£¬ÔòÌáʾÊäÈëÉÌÆ·ÐòºÅ¡¢Ãû³Æ¡¢¼Û¸ñÒªËصÈÏà¹ØÐÅÏ¢*/
printf("input product information record.number is 0 means input is end.\n");
printf("Number is not exceed 9 figures,Name is not exceed 20 characters,range of grade:0.00~1000.00\n");
/*Ñ­»·´Ó¼üÅÌÉ϶ÁÈ¡¹Ë¿ÍÊäÈëµÄÐòºÅ¡¢Ãû³Æ¡¢¼Û¸ñÒªËصÈÏà¹ØÐÅÏ¢*/
while(count <= SIZE)
{
/*ÊäÈëÐòºÅ£¬ÈçΪ0ÔòÍ£Ö¹ÊäÈë*/
printf("\n input 'number = 0' means end input .\n");
printf("number=");
scanf("%ld",&Tmps.Number);
if (Tmps.Number == 0 )
break;







/*ÌáʾÊäÈëÉÌÆ·Ãû³Æ*/
printf("name=");
scanf("%s",Tmps,Name);

/*ÌáʾÊäÈëÉÌÆ·µÄÉÌÆ·¼Û¸ñ*/
printf("price=");
scanf("%f",&Tmps.price);

/*ÌáʾÊäÈëÉÌÆ·ÕÛ¿Û*/
printf("discount=");
scanf("%f",&TmpS.discount);

/*Óù«Ê½×Ô¶¯¼ÆËã»áÔ±¼Û*/
TmpS.memberprice=TmpS.price*TmpS.discount;


printf("\n");
/*ÈçÓöÎÞ·¨Ð´ÈëÎļþµÄÒì³££¬Ôò¼ÓÒÔÌáʾ*/
if(fwrite(&TmpS,sizeof(product),1,fp)!=1
{
printf("\nwrite file %s fail!End with any key\n",DataFile);
perror("write file fail ");
getch( );
exit(1);
}
}
count++;
}
/*Èç¹ûÊäÈëµÄÊý¾ÝÁ¿³¬¹ý×î´óÔÊÐíµÄ·¶Î§£¬ÔòÌáʾÊý¾Ý²»ÄܼÈë*/
if (count>SIZE)
printf(*\nsorry,number of data can not exceed%d\n",SIZE);
fclose(fp);
/*====ÔÚÆÁÄ»ÉÏÏÔʾÎļþÄÚÈÝ====*/
/* clrscr( );*/
printf(*The data you input is store successful %s in file.\n*,DataFile);
printf("Countent as follow:\n");
fp=fpen(DataFile,"rb");
if (fp==NULL)
{
printf("\nopen file%sfail!End with any key \n",DataFile);
perror("Open file fail");
getch( );
exit(1);
}



printf("\nNumber\tName\tprice\tdiscount\tmemberprice\n");
while(fread(&TmpS,sizeof(product),1,fp) != (int)NULL)
{
printf("\n%ld\t%s\t%4.2f\t%4.2f\t\t4.2f\n",TmpS.Number,
TmpS.Name,TmpS.price,TmpS.discount,TmpS.memberprice);
}


fciose(fp);
}
³ÌÐòÇåµ¥£¨4£©£ºadd.c
/*add.c:Ìí¼ÓÉÌÆ·ÐÅÏ¢¼Ç¼*/
#include "stdio.h"
void AddRecord( )
{
FILE *fp = NULL; /*¶¨ÒåÖ¸ÏòÎļþµÄÖ¸Õë*/
product TmpS; /*¶¨Òå½øÐвÙ×÷ʱµÄÁÙʱ½á¹¹Ìå±äÁ¿*/
char DataFile[40] = ""; /*´æ´¢ÉÌÆ·ÐÅÏ¢µÄÎļþÃû*/
int count = 1; /*¼ÆËã¿ÉÊäÈëÊý¾ÝµÄ×î´ó·¶Î§*/
/*====ÊäÈëÒªÌí¼ÓÉÌÆ·ÐÅÏ¢µÄÎļþÃû====*/
printf("\n please input the product information file name to add record:");
printf("\n Notice:Name of file can'texceed 8 characters.suffix can't
exceed 3 characters,part of exceed will be discarded.\n");
gets(DataFile);
/*Èç¹Ë¿ÍûÓÐÊäÈ룬ÔòÑ­»·Ìáʾ¹Ë¿ÍÊäÈë*/
while(*DataFile == ('\0'))
{
printf(*\n please input new file name to store data,end with enter.");
printf("\n Notice:Name of file can'texceed 8 characters,suffix can't
exceed 3 characters.part of exceed will be discarded.\n");
gets(DataFile);
}


fp = fopen (DataFile,"a+");/*a+:µ±Îļþ´æÔÚʱ£¬×·¼Ó£¬µ±Îļþ²»´æÔÚʱ£¬´´½¨*/
/*Èç¹ûµ±Ç°Îļþ²»´æÔÚ£¬Ìáʾ´ò¿ªÎļþʧ°Ü*/
if (fp == NULL)
{
printf(*\n Open file %s fail!End with any key.\n*,DataFile);
perror("Open file fail");


getch( );
exit(1);
}
/*Èç¹û³É¹¦´ò¿ª»ò´´½¨Îļþ£¬ÔòÌáʾÊäÈëÉÌÆ·ÐòºÅ¡¢Ãû³Æ¡¢¼Û¸ñÒªËصÈÏà¹ØÐÅÏ¢*/
printf("input number,name and salary.number is 0 means input is end.\n");
printf("Number is not exceed 9 figures,Name is not exceed 20 characters,range of grade:0.00~1000.00\n");
/*Ñ­»·´Ó¼üÅÌÉ϶ÁÈ¡¹Ë¿ÍÊäÈëµÄÐòºÅ¡¢Ãû³Æ¡¢¼Û¸ñÒªËصÈÏà¹ØÐÅÏ¢*/
while(count <=SIZE)
{
/*ÊäÈëÐòºÅ£¬ÈçΪ0ÔòÍ£Ö¹ÊäÈë*/
printf("\n input 'number =0' means end input.\n");
printf("number=");
scanf("%ld",&TmpS.Number);
if (TmpS.Number == 0 )
break;
/*ÌáʾÊäÈëÉÌÆ·Ãû³Æ*/
printf("name=");
scanf("%s",TmpS.price);

/*ÌáʾÊäÈëÉÌÆ·¼Û¸ñ*/
printf("price=");
scanf("%f",&TmpS.price);

/*ÌáʾÊäÈëÉÌÆ·ÕÛ¿Û*/
printf("discount=");
scanf("%f",&TmpS.discount);


/*Óù«Ê½×Ô¶¯¼ÆËãÉÌÆ·»áÔ±¼Û*/
TmpS.memberprice=TmpS.price*TmpS.discount;


printf("\n");
/*ÈçÓöÎÞ·¨Ð´ÈëÎļþµÄÒì³££¬Ôò¼ÓÒÔÌáʾ*/
if(fwrite(&TmpS,sizeof(product),1,fp)!=1)
{
printf("\nwrite file %s fail!End with any key\n",DataFile);
perror("Write file fail ");
getch( );
exit(1);
}
count++;
}
/*Èç¹ûÊäÈëµÄÊý¾ÝÁ¿³¬¹ý×î´óÔÊÐíµÄ·¶Î§£¬ÔòÌáʾÊý¾Ý²»ÄܼÈë*/
if (count>SIZE)
printf("\nsory,number of data can not exceed%d\n",SIZE);
fclose(fp);







/*====ÔÚÆÁÄ»ÉÏÏÔʾÎļþÄÚÈÝ====*/
/* clrscr( );*/
printf("The data you input is store successful %s in file.\n",DataFile);
printf("Countent as follow:\n");


fp=fopen(DataFile,"rb");
if (fp == NULL)
{
printf("\nOpen file%sfail!End with any key \n",DataFile);
perror("Open file fail");
getch( );
exit(1);
}


printf("\nNumber\tName\tprice\tdiscountmemberprice\n");
while(fread(&TmpS,sizeof(product),1,fp) != (int)NULL)
{
printf(*\n%ld\t%s\t%4.1f\t%4.1f\t%4.1f\n",TmpS.Number,TmpS.Name,TmpS.price,TmpS.discount,Tmps.memberprice);
}


fclose(fp);
}
³ÌÐòÇåµ¥£¨5£©£ºdelete.c
/*delete.c: ɾ³ýÉÌÆ·ÐÅÏ¢¼Ç¼*/
#include "stdio.h"
void DelRecord( )
{
int i,j,k;
long delnum; /*´æ·Å¹Ë¿ÍÊäÈëµÄҪɾ³ýÉÌÆ·ÐòºÅ*/
product TmpS; /*¶¨Òå½øÐвÙ×÷ʱµÄÁÙʱ½á¹¹Ìå±äÁ¿*/
product s[SIZE]; /*SIZE,ÔÚshead.hÍ·ÎļþÖж¨ÒåµÄ³£Á¿£¬ÖµÎª100*/
int recNumber; /*Ô­ÎļþÖеļǼÊý*/
char DataFile[40] = "",next; /*DataFile´æ´¢ÉÌÆ·ÐÅÏ¢µÄÎļþÃû£¬nextΪÊÇ·ñ½øÐÐÏÂÒ»´Îɾ³ý²Ù×÷µÄÑ¡Ïî*/
FILE *fp;/*====fpÖ¸ÕëÖ¸Ïò´æ´¢Êý¾ÝµÄÎļþÃû====*/
printf("\nplease input the name of production information file.\n");
gets(DataFile);
/*Ìáʾ¿Í»§ÊäÈëÒª½øÐÐɾ³ý¼Ç¼µÄÎļþÃû*/
while(*DataFile == ('\0'))
{
printf("\nplease input the name of production information file.\n");
gets(DataFile);
}
begin:
/*ÒÔ¶þ½øÖƶÁµÄ·½Ê½´ò¿ªÎļþ*/
fp=fopen(DataFile,"rb");
if (fp == NULL)
{
printf("\nOpen file %s fail!End with any key\n",DataFile);
perror("Open file fail");
getch( );
exit(1);
}
/*ÊäÈëҪɾ³ýµÄÉÌÆ·ÐòºÅ*/
printf("please input the Product's seatnum which you will delete:");
scanf("%ld",&delnum);
printf("the product you will delete is:%ld\n",delnum);
/*½«ÎļþÖÐÐÅÏ¢´æÈë½á¹¹ÌåÊý×é*/
/*ÓëҪɾ³ýµÄÉÌÆ·ÐòºÅÏàÆ¥ÅäµÄÏдÈëÊý×飬ѭ»·ºóÊý×éÖм´ÎªÈ¥µôÁËҪɾ³ý¼Ç¼ºóµÄÊ£Óà¼Ç¼*/
recNumber=0;
while((fread(&TmpS,sizeof(product),1,fp)) != (int)NULL)
{
if(TmpS.Number!=delnum)
{
s[recNumber].Number = TmpS.Number;
strcpy(s[recNumber].Name,TmpS.Name);
s[recNumber].price = TmpS.price;
s[recNumber].discount = TmpS.discount;
s[recNumber].memberprice = TmpS.memberprice;
recNumber++;
}
}
fclose(fp);
/*====½«É¾³ýºóµÄÊ£Óà½á¹¹Ìå¼Ç¼дÈëÎļþ====*/
fp=fopen(DataFile,"wb+");
if (fp == NULL)
{
printf("\nSet up file %sfail !end with angkey.\n",DataFile);
perror("Set up fail");
getch( );
exit(1);
}
for(i=0; i {
if(fwrite(&s[i],sizeof(product),1,fp)!=1)
{
printf("\nWrite file %s fail!end with angkey.\n",DataFile);
perror("Write file fail!");
getch( );
exit(1);
}
}
fcolse(fp);
/*====ÏÔʾɾ³ýºóµÄÎļþ====*/
fp=fopen(DataFile,"rb");
if (fp == NULL)
{
printf("\nOpen file%sfail!End with angkey \n",DataFile);
perror("Open file fail");
getch( );
exit(1);
}
printf("the file after delete is:\n");
printf("\nNumber \t\tName\tprice\tdiscount\tmemberprice\n");
while(fread(&TmpS,sizeof(product),1,fp) != (int)NULL)
{
if(TmpS.Number!=0)


printf("\n%ld\t%s\t%4.1f\t%4.1f\t%4.1f\n",TmpS.Number,
TmpS.Name,TmpS.price,TmpS.discount,TmpS.memberprice);
}
fclose(fp);
/*ѯÎÊ¿Í»§ÊÇ·ñ¼ÌÐøɾ³ý*/
printf("\nGo on ?(y/n)");
next=getche( );
putchar('\n');
if ( next =='y' || next == 'y') goto begin;
}
³ÌÐòÇåµ¥£¨6£©£ºmodnum.c
/*********************************************************************/
/* monnum.c : ÐÞ¸ÄÉÌÆ·ÐÅÏ¢¼Ç¼ */
/********************************************************************/
#include "stdio.h"
void ModifyByNumber( )
{
int i,j,k;
long modnum; /*´æ´¢¿Í»§ÊäÈëµÄÒªÐ޸ĵÄÉÌÆ·ÐòºÅ*/
/*ÊäÈë¸÷ÏîÐ޸ĺóµÄÐÅÏ¢*/
long Number;
char Name[20];
float price;
float discount;
float memberprice;
product TmpS; /*¶¨Òå½øÐвÙ×÷ʱµÄÁÙʱ½á¹¹Ìå±äÁ¿*/
product s[SIZE];/*SIZE,ÔÚshead.hÍ·ÎļþÖж¨ÒåµÄ³£Á¿£¬ÖµÎª100 */
int recNumber;
char DataFile[40] = "",next;
/*DataFile´æ´¢ÉÌÆ·ÐÅÏ¢µÄÎļþÃû£¬nextΪÊÇ·ñ½øÐÐÏÂÒ»´Îɾ³ý²Ù×÷µÄÑ¡Ïî*/
FILE *fp;/*====fpÖ¸ÕëÖ¸Ïò´æ´¢Êý¾ÝµÄÎļþÃû====*/
/*Ìáʾ¿Í»§ÊäÈëÒª½øÐÐÐ޸ļǼµÄÎļþÃû*/
printf("\nplease input the name of file where data is stored,
end with enter key.\n");
gets(DataFile);
/*Ìáʾ¿Í»§ÊäÈëÒª½øÐÐÐ޸ļǼµÄÎļþÃû*/
while(*DataFile == ('\0'))
{

printf("\nplease input the name of file where data is stored,
end with enter key.\n");
gets(DataFile);

}
begin:
/*ÒÔ¶ÁµÄ·½Ê½´ò¿ªÎļþ£¬ÈçÎļþ²»´æÔÚ£¬Ìáʾ´íÎó*/
fp=fopen(DataFile,"rb");
if (fp == NULL)
{
printf("\nOpen file %s fail!End with any key\n",DataFile);
perror("Open file fail");
getch( );
exit(1);
}
printf("please input the Employee'seatnum which you will modify:");
scanf("%ld",&modnum);
printf("the product you will delete is:%ld\n,modnum");
/*ÊäÈëÒªÐ޸ļǼµÄ¸÷ÏîÄÚÈÝÖµ*/
Number=modnum;
printf("name=");
scanf("%s",Name);

printf("price=");
scanf("%f",&price);

printf("discount=");
scanf("%f",&discount);

/*Óù«Ê½×Ô¶¯¼ÆËãÉÌÆ·»áÔ±¼Û*/
memberprice=peice*discount;
/*½«ÎļþÖÐÒªÐ޸ĵÄÐÅÏ¢´æÈë½á¹¹ÌåÊý×é*/
recNumber=0;
/*Ñ­»·½«ÎļþÊý¾Ý¶ÁÈë½á¹¹ÌåÊý×飬
ÈçÎļþÖеÄÊý¾ÝÉÌÆ·ºÅºÍÒªÐ޸ĵÄÉÌÆ·ºÅ²»·û£¬ÔòÔ­ÑùдÈëÊý×飬
ÈçÎļþÖÐÊý¾ÝµÄÉÌÆ·ºÅºÍÒªÐÞ¸ÄÉÌÆ·ºÅÆ¥Å䣬
Ôò¸ù¾Ý¹Ë¿ÍÊäÈëµÄ¸÷ÏîÐÞ¸ÄÄÚÈÝÖØи³Öµ£¬¼´Ð޸ģ¬²¢Ð´ÈëÊý×é*/
while((fread(&TmpS,sizeof (product),1,fp)) != (int)NULL)
{
if(TmpS.Number!=modnum)
{
s[recNumber].Number = TmpS.Number;
strcpy(s[recNumber].Name,TmpS.Name);
s[recNumber].price = TmpS.price;
s[recNumber].discount = TmpS.discount;
s[recNumber].memberprice = TmpS.memberprice;
recNumber++;
}
else
{
s[recNumber].Number = Number;
strcpy(s[recNumber].Name,Name);
s[recNumber].price = price;
s[recNumber].discount = discount;
s[recNumber].memberprice = memberprice;
recNumber++;
}
}
fclose(fp);
/*====½«Ð޸ĺóµÄ½á¹¹ÌåÊý×é¼Ç¼дÈëÎļþ====*/
fp=fopen(DataFile,"wb+");
if (fp == NULL)
{
printf("\nSet up file %sfail !end with anykey.\n",DataFile);
perror("Set up fail");
getch( );
exit(1);
}


for(i=0; i{
if(fwrite(&s[i],sizeof(product),1,fp)!=1)
{
printf("\nWrite file %s fail!end with anykey.\n",DataFile);
perror("Write file fail!");
getch( );
exit(1);
}
}
fclose(fp);
/*====ÏÔʾÐ޸ĺóµÄÎļþ====*/
fp=fopen(DataFile,"rb");
if (fp == NULL)
{
printf("\nOpen file%sfail!end with any key \n",DataFile);
perror("Open file fail");
getch( );
exit(1);
}
printf("the file after modify is:\n");
printf("\nNumber\t\tName\tprice\tdiscount\tmemberprice\n");
while(fread(&TmpS,sizeof(produnt),1,fp) != (int)NULL)
{
if(TmpS.Number!=0)
printf("\n%ld\t%s\t%4.1f\t%4.1f\t%4.1f\n",TmpS.Number,
TmpS.Name,TmpS.price,TmpS.discount,TmpS.memberprice);
}
fclose(fp);
/*ÌáʾÊÇ·ñ½øÐÐÏÂÒ»´ÎÐÞ¸Ä*/
printf("\nGo on ?(y/n)");
next=getche( );
putchar('\n');
if( next =='y' || next =='y') goto begin;
}
³ÌÐòÇåµ¥£¨7£©£ºqname.c
/*=======quame.c:°´Ãû³Æ²éѯÉÌÆ·ÐÅÏ¢¼Ç¼===============*/
#include "stdio.h"
void QueryByName()
(
int result=0;/*"result=1"˵Ã÷²éѯ³É¹¦£¬·´Ö®²éÕÒʧ°Ü*/
product TmpS;/*¶¨Òå½øÐвÙ×÷ʱµÄÁÙʱ½á¹¹Ìå±äÁ¿*/



char Xingming[20];/*Óû§ÊäÈëÒª²éѯµÄÉÌÆ·Ãû³Æ*/
char DateFile[40] = ""¡¢next
/*DateFile´æ´¢ÉÌÆ·ÐÅÏ¢µÄÎļþÃû£¬nextΪÊÇ·ñ½øÐÐÏÂÒ»´Îɾ³ý²Ù×÷µÄÑ¡Ïî*/
FILE *fp=NULL;
/*====fpÖ¸ÕëÖ¸Ïò´æ´¢Êý¾ÝµÄÎļþÃû====*/
/*ÌáʾÓû§ÊäÈëÒª²éѯµÄÎļþÃû*/
printf("\nplease input the name of product information file .\n");
gets(DateFile);
/*ÌáʾÓû§ÊäÈëÒª²éѯµÄÎļþÃû*/
while(*DateFile == ('\0'))
{
printf("\nplease input the name of product information file .\n");
gets(DateFile);
}
/*ÌáʾÓû§ÊäÈëÒª²éѯµÄÎļþÃû*/
begin:
result=0;
printf("please input the name of product which needs look up (under 20 bit figure).\n");
scanf("%s".&Xingming);
getchar();
/*ÒÔ¶Á·½Ê½´ò¿ªÎļþ*/
pf=fopen (DateFile ."r");
if (fp=NULL)
{
printf("\nOpen file%sfale£¡Eed with any key .\n".DateFile);
perror(open file fail");
getch();
exit(1);
}
/*Ñ­»·²éÕÒºÍÊäÈëÃû³ÆÏàÆ¥ÅäµÄÉÌÆ·ÐÅÏ¢¼Ç¼£¬Èç¹û²éÕÒµ½£¬ÔòÊä³ö½á¹û*/
while(feof(fp==0))
{
if(fread(&TmpS.sizeof(product).1,fp)!=(int)NULL)
(
if (stricmp(Tmps,Name,xingming)==0)
{
printf ("\n Find:)\n");
printf("\nNumber=%ld Name=%s price=%4.if discount=%4.if meberprice=%4.if\n".TmpS.Number.Name.Tmps.price.TmpS.discount.TmpS.memberprice);
result=1;/*"result=1"˵Ã÷ÕÒµ½Á˸ÃÉÌÆ·µÄ¶ÔÓ¦ÐÅÏ¢.*/
}
}
}
fclose(fp);
/*ÌáʾÓû§ÒѲ鵽½á¹û²¢Ñ¯ÎÊÊÇ·ñ¼ÌÐø²éÕÒ*/
if (result == 0 )
{
printf("There is no date of this product in the file!")
}
printf("\nGo on ?(y/n)");
next=getche();
putchar('\n');
if (next=='y' || next =='y')goto begin ;
}
³ÌÐòÇåµ¥£¨8£©£ºsmprice.c
/*smemberprice.c:°´ÉÌÆ·»áÔ±¼ÛÑ­ÐòÅÅÐò*/
#include "stdio.h"
void SortByMenberPrice()
{
int i.j.k;
product Tmps; /*¶¨Òå½øÐвÙ×÷ʱµÄÁÙʱ½á¹¹Ìå±äÁ¿*/
product s[SIZE];/*SIZE,ÔÚshead.hÍ·ÎļþÖж¨ÒåµÄ³£Á¿£¬ÖµÎª100*/
int recNnmber =0
char DateFile[40] =" "; /*DateFile´æ´¢ÉÌÆ·ÐÅÏ¢µÄÎļþÃû*/
FILE *fp ;/*====fp Ö¸ÕëÖ¸Ïò´æ´¢Êý¾ÝµÄÎļþÃû====*¡¢
/*ÌáʾÓû§ÊäÈëÒª½øÐÐÅÅÐòµÄÎļþÃû*/
printf("\nplease input the name of product information file.\n");
get(DateFile);
/*ÌáʾÓû§ÊäÈëÒª½øÐÐÅÅÐòµÄÎļþÃû*/
while (DateFile == ('\0'))
{
printf("\nplease input the name of product information file.\n");
get(DateFile);
}
/*ÒÔ¶ÁµÄ·½Ê½´ò¿ªÎļþ£¬Èç¹ûÎļþ²»´æÔÚ£¬Ìáʾ´íÎó*/
fp =fopen(DateFile."rb");
if (fp=NULL)
{
printf("\nopen file %s fail!End with any key\n".DateFile);
perror("Open file fail ");
getch();
exit();
}
/*½«ÎļþÖØÒªÅÅÐòµÄÐÅÏ¢´æÈë½á¹¹ÌåÊý×é*/
while ((fread(&TmpS.sizeof(product).1.fp))!=(int)NULL)
{
s[reNumber].Number= TmpS.Number;
strcpy(s[reNumber].Name.TmpS.Name);
s[reNumber].price=TmpS.price;
s[reNumber].discount=TmpS.discount;
s[reNumber].memberprice=TmpS.memberprice;
reNember++;
}
fclose(fp);
/*===Èç¹ûÎļþÖÐÓмǼ£¬Ôò½«¸÷Ìõ¼Ç¼°´ºÏ¼ÆµÃÅÅÐò===*/
if(recNumber>1)
{
/*====ÓÃÑ¡ÔñÅÅÐòµÄ·½·¨½øÐкϼƵÃÅÅÐò====*/
for(i=0;i {
k=i;
for (j=i+1£»j {
if (s[k].memberprice }
TmpS .Number =s[k].Number;
strcpy(TmpS,Name.s[k].Name);
TmpS .price=s[k].price;
TmpS .discount=s=[k].discount;
TmpS .memberprice =s[k].memberprice;



s[k].Number=s[i].Number;
strcpy(s[k].Name.s[i].Name);
s[k].price=s[i].price;
s[k].discount=s[i].discount;
s[k].memberprice=s[i].memberprice;



s[k].Number=TmpS.Number;
strcpy(s[k].Name.TmpS.Name);
s[k].price=TmpS.price;
s[k].discount=TmpS.discount;
s[k].memberprice=TmpS.memberprice;
}
/*====½«ÅÅÐòºÃµÄ½á¹¹Ìå¼Ç¼дÈëÎļþ====*/
fp=fopen(DateFile."wb+");
if(fp== NULL)
{
printf("\Set up file %sfail !end with anykey .\n".DateFile);
perror("Set up fail");
getch();
exit();
}
for(i=0;i {
if (fwrite(&s[i].sizeof(product).1.fp)!=1)
{
printf("\nwrite file %sfail !end with anykey .\n".DateFile);
perror("Write file fail ");
getch();
exit();
}
}
fclose(fp);
}
/*====ÏÔʾÅÅÐòºóµÄÎļþ====*/

printf("\the product's information in file %s is as flow:.\n".DateFile);
fp =fopen(DateFile."rb");
if(fp==NULL)
{
printf("\nopen file %sfail !End with anykey .\n".DateFile);
perror("Open file fail");
getch();
exit();
}
printf("\nNumber\tName\tprice\tdiscount\tmemberprice\n");
while(fread(&TmpS.sizeof(product).1.fp)!=(int)NULL)
{
printf("n%ld\t%s\t%4.2f\t%4.2f\t%4.2f\n".TmpS.Number.TmpS.Name.TmpS.price.TmpS.discount.TmpS.memberprice);
}
fclose(fp);
}
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 1 ÌõÆÀÂÛ

  1. embedman ÓÚ 2009-04-17 00:04:08·¢±í:

    Linuxϱà³Ì¿Ï¶¨ÐèÒªMakefile²ÅÄܱàÒë³ö´úÂ룬ÓÃtouch Makefile ÃüÁн¨ Ò»¸öMakefileÎļþ£¬È»ºó²Î¿¼GNU make ÖÐÎÄÊֲᣨÍøÉϺࣩܶ£¬×Ô¼º±àдMakefile£¬±àºÅÖ®ºó±£´æ£¬ÔÚ¹¤×÷Ŀ¼Ï ÊäÈë makeÃüÁî ¾ÍÄܱàÒë