博文
图书馆管理系统(2005-09-18 11:26:00)
摘要: #include <stdio.h>#include <stdlib.h>#include <conio.h>
struct BOOK { int id,usr[10],total,store,days[10]; char name[31],author[21]; }books[100];/*上面是结构体的定义,用于存放书籍及借书的信息。*/
void page_title(char *menu_item) { clrscr(); printf(">>> 图 书 管 理 系 统 <<<\n\n- %s -\n\n",menu_item); }/*上面是打印页眉的函数,同时通过参数menu_item,可以显示当前的状态。*/
void return_confirm(void) { printf("\n按任意键返回……\n"); getch(); }/*上面是返回前请求确认的函数,以便在返回前观察结果*/
int search_book(void) { int n,i; printf("请输入图书序号:"); scanf("%d",&i); for(n=0;n<100;n++) { if(books[n].id==i) { printf("书名:%s\n",books[n].name); printf("作者:%s\n",books[n].author); printf("存数:%d of ",books[n].store); printf("%d\n",books[n].total); return n; } } printf("\n输入错误或无效图书序号.\n"); return -1; }/*上面的函数是在数组中找到图书号匹配的记录,显示其信息并返 回......
学生成绩管理(2005-09-18 11:26:00)
摘要: #include <stdio.h>#include <stdlib.h>#include <conio.h>
int INDEX[32];struct STUDENT { int id,age,chinese,math,english; char name[21]; }students[32];
void page_title(char *menu_item) { clrscr(); printf(">>> 学 生 管 理 系 统 <<<\n\n- %s -\n\n",menu_item); }
void return_confirm(void) { printf("\n按任意键返回……\n"); getch(); }
void student_new(void) { int n; page_title("录入学生基本信息"); for(n=0;n<32;n++) if(students[n].id==0) break; printf("学号:"); scanf("%d",&students[n].id); printf("姓名:"); scanf("%s",&students[n].name); printf("年龄:"); scanf("%d",&students[n].age); return_confirm(); }
int search_id(void) { int n,i; printf("请输入学生学号:"); scanf("%d",&i); for(n=0;n<32;n++) { if(students[n].id==i&&students[n].id!=0) { printf("学号:%d\n",students[n].id......
泊车管理(2005-09-18 11:25:00)
摘要: #include<stdio.h>#include<conio.h>#include<stdlib.h>
int cars[16][3];
void car_park(void) { int n,m,o; for(n=0;n<16;n++) if(cars[n][0]==0) break; if(n==16) { printf("\n便道很拥挤.\n"); getch(); return; } printf("\n泊车-请输入车牌:"); scanf("%d",&o); for(m=0;m<16;m++) if(cars[m][0]==o) break; if(m!=16) { printf("\n此车已泊.\n"); getch(); return; } cars[n][0]=o; if(n<10) { printf("请输入当前时:"); scanf("%d",&cars[n][1]); printf("请输入当前分:"); scanf("%d",&cars[n][2]); return; } else printf("\n请先在便道上等候车位"); getch(); }void car_get() { int n,o,p,q,r; printf("\n取车-请输入车牌:"); scanf("%d",&o); for(n=0;n<16;n++) if(cars[n][0]==o) break; if(n==16) { printf("\n没有这个车牌.\n"); getch(); return; } printf("请输入当前时:......
C语言中字符串拷贝函数的实例(2005-09-18 11:24:00)
摘要: #include <string.h> /* strcpy */
void SafeCopy(char *Dest, int DestSize, char *Source);
main(){ char Text1[20]="Tracy Sorrell"; /* string buffer */ char Text2[10]="Martin"; /* string buffer */
printf (" Original string contents are: %s\n", Text2);
SafeCopy(Text2, sizeof(Text2), Text1); printf (" New string contents are: %s\n", Text2);
strcpy(Text2, "Alex"); printf (" Final string contents are: %s\n", Text2);
}
/****************************************************************/
void SafeCopy( char *Dest, /* Destination buffer. */ int DestSize, &......
C语言中的时间函数及使用实例(2005-09-18 11:24:00)
摘要: #include <stdio.h> /* NULL */#include <time.h> /* ctime, asctime */
main(){ time_t now; /* define 'now'. time_t is probably * a typedef */
/* Calender time is the number of * seconds since 1/1/1970 */
now = time((time_t *)NULL); /* Get the system time and put it * into 'now' as 'calender time' */
printf("%s", ctime(&now)); /* Format data in 'now' * NOTE that 'ctime' inserts a * '\n' */
/*************************......
C语言中的格式化写入文件函数及使用实例(2005-09-18 11:24:00)
摘要: #include <stdio.h>
main(){
FILE *Ptr;
char Line[256];
/* ... Open a file for output. */
Ptr = fopen("/tmp/OutputFile", "w");
while(gets(Line)) /* Get data from stdin */ { fprintf(Ptr, "%s\n", Line); /* Send data to file. */ }
fclose(Ptr);}......
C语言中的打开文件函数及使用实例(2005-09-18 11:23:00)
摘要: #include <stdio.h>
main(){ int c; /* Character read from the file. */ FILE *ptr; /* Pointer to the file. FILE is a structure defined in <stdio.h> */
/* Open the file - no error checking done */ ptr = fopen("/etc/hosts","r"); /* Read one character at a time, checking for the End of File. EOF is defined in <stdio.h> as -1 */ while ((c = fgetc(ptr)) ! ......
一个猜数游戏,判断一个人反应快慢(2005-09-18 11:23:00)
摘要: #include "time.h"#include "stdlib.h"#include "stdio.h"main(){char c;clock_t start,end;time_t a,b;double var;int i,guess;srand(time(NULL));printf("do you want to play it.('y' or 'n') \n");loop:while((c=getchar())=='y'){i=rand()%100;printf("\nplease input number you guess:\n");start=clock();a=time(NULL);scanf("%d",&guess);while(guess!=i){if(guess>i){printf("please input a little smaller.\n");scanf("%d",&guess);}else{printf("please input a little bigger.\n");scanf("%d",&guess);}}end=clock();b=time(NULL);printf("\1: It took you %6.3f seconds\n",var=(double)(end-start)/18.2);printf("\1: it took you %6.3f seconds\n\n",difftime(b,a));if(var<15)printf("\1\1 You are very clever! \1\1\n\n");getch(); } }......
时间显示(2005-09-18 01:43:00)
摘要:#include <stdio.h>#include <time.h>
int main(void){ time_t t;
t = time(NULL);
printf("Current date is %s", ctime(&t));
t -= 24L*60L*60L; /* Back up to same time previous day */
stime(&t); printf("\nNew date is %s", ctime(&t));
getch(); return 0;}......
人事记录(2005-09-18 01:43:00)
摘要:#include <stdio.h>#include <conio.h>
int main(void){ char label[20]; char name[20]; int entries = 0; int loop, age; double salary;
struct Entry_struct { char name[20]; int age; float salary; } entry[20];
/* Input a label as a string of characters restricting to 20 characters */ printf("\n\nPlease enter a label for the chart: "); scanf("%20s", label); fflush(stdin); /* flush the input stream in case of bad input */
/* Input number of entries as an integer */ printf("How many entries will there be? (less than 20) "); scanf("%d", &entries);
fflush(stdin); /* flush the input stream in case of bad input */
/* input a name restricting input to only letters upper or lower case */ for (l......
