/*
*File name:  classmate.c
*Author:    Vinco Zhang  e-mail: xuyunzhang693@qq.com
*Description: this program is written for the course design of "创新实验",it have been tested in
*Red Hat 5(a linux os).when run it, firstly it create a file classmate.ini, then input the data of your *classmate, it will be recorded into the classmate.ini, finally it will print the data in the file. you also *can clean the file in the last by the function fclean()
*Develop environment: linux red hat 5 //gcc -o classmate classmate.c
*Copyright: All Reserved
*/
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<time.h>
#include<malloc.h>

/*****************************************************/

#define LIST_INIT_SIZE 60
#define LEN sizeof(struct classmate)
//#define DEF_INIT_P(p)  ClassMate p=(ClassMate )malloc(LEN)
//#define DEF_NULL_P(p)  ClassMate p=NULL
//#define llong long long
#define llong __int64

typedef struct classmate
{
    unsigned llong No;
    char name[30];
    char cellphone[15];
    //you can add more members such as QQ, home address .etc
    struct classmate*  next;
}* ClassMate;
//struct classmate classmate;
int n;
ClassMatelist_creat(ClassMate head);
ClassMate list_insert(ClassMate head,ClassMate classmate);
ClassMate list_delete(ClassMate head, unsigned llong No);
void list_print(ClassMatehead);

int list_write(ClassMate head);
int list_read(ClassMate head);
int parse_line_to_list(char* line,ClassMate head);
int fclean(void);
int time_print(void);

/*****************************************************/

int main(void)
{    
    ClassMate head,p;
    //DEF_INIT_P(head);
    //DEF_INIT_P(p);
    struct classmate tp={2007142103,"li","15307135540",p};
    ClassMate classmate=&tp;
    unsigned llong No=2007142105;

time_print();
    printf("len=sizeof(struct classmate)=%d\n",LEN);
    head=list_creat(head);
    head=list_delete(head,No);
    list_print(head);
    list_write(head);
    list_read(head);
    list_print(head);
    //free(head);
    //free(p);
    //fclean();
    return 0;
}
/*****************************************************/

int fclean(void)
{
    FILE* fclm;
    int i=0;
    char line[128];
    if((fclm=fopen("classmates.ini","w"))==NULL)//w+
    {
        printf("classmates.ini open fail!!\n");
        return 0;
    }
    printf("the file have been cleaned now!\n");
    fclose(fclm);
    return 1;
}

ClassMate list_creat(ClassMate head)
{    
    //p1 point to the last one elem of the list (the elem inputed just now)
    //p2 point to the second last elem of the list
    ClassMate  p1=NULL,p2=NULL;
    n=0;
     p1=(ClassMate)malloc(LEN);
    p2=(ClassMate)malloc(LEN);
    //DEF_INIT_P(p1);
    //DEF_INIT_P(p2);
    printf("please input as follw format,or enter 0 for exit from input model:\nNo:\tname:\t\tcellphone:\n");
    scanf("%ld",&p1->No);if(p1->No==0) goto exit;
    scanf("%s",p1->name);
    scanf("%s",p1->cellphone);
    printf("you have input:\nNo:%ld\tname:%s\t\tcellphone:%s\n",p1->No,p1->name,p1->cellphone);
    printf("[++++++++++++++++++++++++++++++++++++++++++++++]\n");
    head=list_insert(head,p1);
    list_print(head);
    while((p1->No)!=0)
    {
        n=n+1;
        p1=(ClassMate )malloc(LEN);
        printf("please input as follw format,or enter 0 for exit from input model:\nNo:\tname:\t\tcellphone:\n");
        scanf("%ld",&p1->No);if(p1->No==0) goto exit;
        scanf("%s",p1->name);
        scanf("%s",p1->cellphone);
        printf("you have input:\nNo:%ld\tname:%s\t\tcellphone:%s\n",p1->No,p1->name,p1->cellphone);
        printf("[++++++++++++++++++++++++++++++++++++++++++++++]\n");
        head=list_insert(head,p1);
        list_print(head);
    }
    exit:
    printf("you have input '0',so exit from the input now!!\n");
    printf("[++++++++++++++++++++++++++++++++++++++++++++++]\n");

free(p1);
    free(p2);
    return (head);
}
ClassMate  list_insert(ClassMate head,ClassMate classmate)
{
    //p0 point to the data will be insert into the list
    //p1 point to the last one elem of the list
    //p2 point to the second last elem of the list
    ClassMate p0,p1,p2;
    //DEF_INIT_P(p0);
    //DEF_INIT_P(p1);
    //DEF_INIT_P(p2);
    p1=head;
    p0=classmate;

if(head==NULL)
    {
        head=p0;;
        p0->next=NULL;
    }
    else
        {
            while((p0->No > p1->No) && (p1->next!=NULL))
            {
                p2=p1;
                p1=p1->next;
            }
            if(p0->No <= p1->No)
            {
                if(head==p1)head=p0;
                else p2->next=p0;
                p0->next=p1;
            }
            else
                {
                    p1->next=p0;
                    p0->next=NULL;
                }
        }
    printf("you have inserted the following into the list just now!\nNo:%ld\tname:%s\t\tcellphone:%s\n",classmate->No,classmate->name,classmate->cellphone);
    n=n+1;
    printf("[++++++++++++++++++++++++++++++++++++++++++++++]\n");
    //free(p0);
    //free(p1);
    //free(p2);
    return(head);
}
ClassMate  list_delete(ClassMate  head, unsigned llong No)
{
    //p1 point to the last one elem of the list
    //p2 point to the second last elem of the list
    
    ClassMate p1;
    ClassMate p2;
    printf("you want to detele classmate from the list whose No=%ld;\n",No);
    //DEF_INIT_P(p1);
    //DEF_INIT_P(p2);
    if(head==NULL)
    {
        printf("\nthe list is NULL,delete fail!!!\n");
        goto end;
    }
    p1=head;
    while(No != p1->No && p1->next != NULL)
    {
        p2=p1;
        p1=p1->next;
    }
    if(No==p1->No)
    {
        if(p1==head) head=p1->next;
        else p2->next=p1->next;
        printf("you have deleted the following from the list just now:\nNo:%ld\tname:%s\t\tcellphone:%s\n",p1->No,p1->name,p1->cellphone);
        n=n-1;
    }
    else printf("but %ld not been found,delete fail!!!\n",No);
    end:
    printf("[++++++++++++++++++++++++++++++++++++++++++++++]\n");
    free(p1);
    free(p2);
    return(head);
}

void list_print(ClassMate  head)
{
    //ClassMate  p;
    DEF_INIT_P(p);
    p=head;
    printf("print the list record now!\n");
    if(head!=NULL)
    {
        do
        {
            printf("No:%ld\tname:%s\t\tcellphone:%s\n",p->No,p->name,p->cellphone);
            p=p->next;
        }while(p!=NULL);
    }
    free(p);
    printf("[++++++++++++++++++++++++++++++++++++++++++++++]\n");
}

int list_write(ClassMate  head)
{
    ClassMate  p=head;
    FILE* fclm;
    char line[128+1];
    int i=0;
    if((fclm=fopen("classmates.ini","a"))==NULL)//a+
    {
        printf("classmates.ini open fail!!\n");
        return 0;
    }
    if(head!=NULL)
    {
        do
        {
        snprintf(line,128+1,"No:%ld\tname:%s\t\tcellphone:%s\n",p->No,p->name,p->cellphone);
            fprintf(fclm,"%s",line);
            //printf("No:%ld\tname:%s\t\tcellphone:%s\n",p->No,p->name,p->cellphone);
            printf("you have writed the following line to the file:\n%s\n",line);
            p=p->next;
        }while(p!=NULL);
    }
    fclose(fclm);
    return 1;
}
int list_read(ClassMate  head)
{
    ClassMate  p=head;
    FILE* fclm;
    char line[128+1];
    char ch;
    int i=0;
    if((fclm=fopen("classmates.ini","r"))==NULL)
    {
        printf("classmates.ini open fail!!\n");
        return 0;
    }
    //fseek(fclm,0,SEEK_SET);
    rewind(fclm);
    printf("read the file now!\n");
    ch=fgetc(fclm);
    do
    {    
        fseek(fclm,-1,SEEK_CUR);
        fgets(line,128+1,fclm);
        ++i;
        printf("get the line[%d]=%s",i,line);//fputs(line,stdout);
        parse_line_to_list(line,head);
        ch=fgetc(fclm);
    }while(ch!= EOF);
    fclose(fclm);
    return 1;
}
int parse_line_to_list(char* line,ClassMate  head)
{
    //ClassMate  classmate;
    DEF_INIT_P(classmate);
    char* p=line;
    int i;
    unsigned llong No=0,tmp;
    char name[30];
    char cellphone[15];
    p=strstr(p,"No:");
    p=strstr(p,":");
    if(p==NULL) return 0;
    while(!isdigit(*p)) p++;
    while(isdigit(*p))
    {
        tmp=(*p)-'0';
        No=10*No+tmp;
        p++;
    }
    p=strstr(p,"name:");
    p=strstr(p,":");
    p++;
    i=0;
    while(!isalnum(*p)) p++;
    while(isalnum(*p))
    {
        name[i++]=*(p++);
    }
    name[i]='\0';
    p=strstr(p,"cellphone:");
    p=strstr(p,":");
    p++;
    i=0;
    while(!isdigit(*p)) p++;
    while(isdigit(*p))
    {
        cellphone[i++]=*(p++);
    }
    cellphone[i]='\0';
    classmate->No=No;
    //strncpy(classmate->name,name,strlen(name));
    //strncpy(classmate->cellphone,cellphone,strlen(cellphone));
    strcpy(classmate->name,name);
    strcpy(classmate->cellphone,cellphone);
    head=list_insert(head,classmate);
    //free(classmate);
    return 0;
}
int time_print(void)
{
    time_t t=time(0);
    char tmp[64];
    strftime(tmp,sizeof(tmp),"date:%Y-%m-%d %A \ntime:%X   %j  %z %Z",localtime(&t));
    puts(tmp);
    return 0;
}

classmate.c相关推荐

  1. java.lang.ClassNotFoundException: com.fasterxml.classmate.TypeResolver

    异常如下: 二月 23, 2018 11:36:48 上午 org.springframework.web.context.ContextLoader initWebApplicationContex ...

  2. com/fasterxml/classmate/TypeResolver

    我之前遇到过这个问题,我的问题出在com/fasterxml/classmate/TypeResolver : 我根据一个教程学习hibernate使用了如下创建方法: ServiceRegistry ...

  3. 使用swagger org.fasterxml.classmate ResolvedParameterizedMember找不到

    使用swagger org.fasterxml.classmate ResolvedParameterizedMember找不到 使用swagger 2.6.1 org.fasterxml.class ...

  4. java.lang.NoClassDefFoundError: com/fasterxml/classmate/TypeResolver

    解决办法: 下载最新的:classmate-1.0.0 http://maven.outofmemory.cn/com.fasterxml/classmate/

  5. 使用hibernate的validator时提示java.lang.NoClassDefFoundError: com/fasterxml/classmate/TypeResolver

    异常提示缺少类,需要导入jar包: 需要导入hibernate中的classmate.jar即可

  6. org.fasterxml.classmate ResolvedParameterizedMember找不到

    添加一下依赖即可 <dependency> <groupId>com.fasterxml</groupId> <artifactId>classmate ...

  7. Maven项目报错:Caused by: java.lang.NoClassDefFoundError: com/fasterxml/classmate/Filter

    一.问题描述 项目一运行就报错: Caused by: java.lang.NoClassDefFoundError: com/fasterxml/classmate/Filterat org.hib ...

  8. spring mvc校验部分属性,springmvc校验属性,java.lang.ClassNotFoundException: com.fasterxml.classmate.Filter

    spring mvc校验部分属性,springmvc校验属性 转载请注明: TheViper http://www.cnblogs.com/TheViper 基于JSR303注解校验 问题的出现 一个 ...

  9. 第三人称的英语作文我和我的计算机,英语作文:我的同学My Classmate

    英语作文:我的同学My Classmate 同学应该是我们读书时候最熟悉的人了,每天都在一起学习,应该是互相很了解的人了,这类的英语作文的关键是:用精炼的语言来描述你的同学. 请以"My C ...

最新文章

  1. 区块链基础:理论和术语
  2. React Button 使用onClick 定义 antd 登录页面
  3. JS数组去重的6种算法实现
  4. Tensorflow基本开发步骤——以逻辑回归拟合二维数据为例
  5. Acwing第 14 场周赛【完结】
  6. 让Lua支持Linq吧
  7. Hive _偏门常用查询函数(二)附带实例(列转行、窗口函数)
  8. 55寸鸿蒙安卓,深网|荣耀智慧屏发布:搭载鸿蒙系统 配55英寸屏3799元起
  9. 比较默认对象和默认约束的异同_UE4对象类类型引用和类默认对象(Class Default Object,简称CDO)...
  10. Android--Fragment基本介绍
  11. 【渝粤教育】国家开放大学2018年春季 3922T汽车运用基础 参考试题
  12. hdu2586 lca倍增法
  13. 软件产品测试报告模板
  14. 数据结构4:静态链表
  15. 13号线ab线规划图_北京地铁13号线将拆分为AB两线
  16. 树莓派python控制两个舵机_利用树莓派,光敏电阻和小型舵机实现自动获取 《最终幻想 X HD重制版》 连续避雷200次奖杯...
  17. 改了dns服务器有没有影响,dns改成114有危险吗_dns改了有什么影响
  18. 008-break语句与continue语句的使用,循环嵌套
  19. joycon手柄拆解_爱活电刑室 | 撬开海拉尔的大门! 任天堂Switch全拆解
  20. Ubuntu16.04 安装 OPENCV详细教程 避坑

热门文章

  1. Week 3 测验 Regularization【Maching learning】
  2. Java判断闰年,统计1900年后闰年数
  3. 了解僵尸网络攻击:什么是僵尸网络,它如何传播恶意软件以及如何保护自己?
  4. 明代主要科学技术成就
  5. 视频笔记:理解 channels - Kavya Joshi
  6. 30年初心坚守 神州信息用数字技术实现普惠金融
  7. 暗黑3服务器维护,暗黑3 PTR服务器维护并将发布新版本补丁
  8. sum 矩阵求和 matlab
  9. 程序员之间的斗图大作战! 代码可乱, 斗图不能输
  10. 数字电路基础与Quartus入门