c Dwrite Program

/*  HELLO.C -- Hello, world */


#include "stdio.h"
#include "conio.h"
#include "io.h"
#include <dos.h>
#include <sys/stat.h>
#include <string.h>
#include <time.h>
#include <ctype.h>


typedef struct Data
{
    char SN[25];
    char MAC[25];
    char STATE[4];
    char STATION[25];
    char PARAGRAPH[4];
    char OP[25];
    char BIOS[25];
    char LITIME[25];
}TEDATA;




char *ReadText(char *FileName)
{
     FILE *Fp;
     char Temp[25];
     memset(Temp,0,sizeof(Temp));
     Fp=fopen(FileName,"r");
     if(Fp==NULL)
     {
         printf("Read %s Text Not Find",FileName);
         getch();
         exit(1);
     }
     fgets(Temp,25,Fp);
     Temp[strlen(Temp)]='\0';
     printf("Text %s Read Passed\n",FileName);
     return Temp;
}


int WriteData(char *FileName,char *TestData)
{
    FILE *Fp;
    Fp=fopen(FileName,"a");
    if(Fp==NULL) return 0;
    fputs(TestData,Fp);
    fputs("\n",Fp);
    fclose(Fp);
    return 1;


}


char *NowTime(void)
{
    char *da;
    time_t nowtime;
    struct tm *timeinfo;
    int year,month,day,hour,min,sec;
    nowtime=(NULL);
    time(&nowtime);
    timeinfo=localtime(&nowtime);
    year=timeinfo->tm_year+1900;
    month=timeinfo->tm_mon+1;
    day=timeinfo->tm_mday;
    hour=timeinfo->tm_hour;
    min=timeinfo->tm_min;
    sec=timeinfo->tm_sec;
    sprintf(da,"%4d/%02d/%02d %02d:%02d:%02d",year,month,day,hour,min,sec);
    return da;
}


int FccChar(char *TestData,int len)
{
    char ValueStr[255]={'A','B','C','D','D','E','F','G','H','I','J','K',
    'L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1',
    '2','3','4','5','6','7','8','9','-','_'};
    int x=0,y=0,total=0;
    for(x=0;x<len;x++)
    {
        for(y=0;y<strlen(ValueStr);y++)
        {
           if(toupper(TestData[x])==ValueStr[y])
           {
               total++;
               break;
           }
           else if(y==strlen(ValueStr)-1)return total;
        }
    }
    return total;
}


int main(void)
{
    int x=0,n=0;
    TEDATA log={NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
    char Buffer[255],FileName[255];
    memset(Buffer,0,sizeof(Buffer));
    NowTime();
    clrscr();
    textbackground(BLACK);
    textcolor(GREEN);
    strcpy(log.SN,ReadText("SN.TXT"));
    printf("%c",log.SN[13]);
    while(log.SN[x]!='\0')
    {
        x++;
    }
    x=x-1;
    n=FccChar(log.SN,x);
    if(n>=18)n=18;
    log.SN[n]='\0';
    printf("str=%s,len=%d\n",log.SN,n);
    strcpy(log.MAC,ReadText("MAC.TXT"));
    strcpy(log.STATE,"0K");
    strcpy(log.STATION,ReadText("STATION.DAT"));
    strcpy(log.PARAGRAPH,"021");
    strcpy(log.OP,ReadText("OP.DAT"));
    strcpy(log.LITIME,NowTime());
    strcpy(log.BIOS,ReadText("BIOS.DAT"));
    strcpy(Buffer,log.SN);
    strcat(Buffer,",");
    strcat(Buffer,log.MAC);
    strcat(Buffer,",");
    strcat(Buffer,log.STATE);
    strcat(Buffer,",");
    strcat(Buffer,log.STATION);
    strcat(Buffer,",");
    strcat(Buffer,log.PARAGRAPH);
    strcat(Buffer,",");
    strcat(Buffer,log.OP);
    strcat(Buffer,",");
    strcat(Buffer,log.BIOS);
    strcat(Buffer,",");
    strcat(Buffer,log.LITIME);
    Buffer[strlen(Buffer)]='\0';
    if(access("s:\\record.p",0)==-1)
    {
        clrscr();
        textbackground(0);
        textcolor(2);
        printf("Link Serve Err!!");
        return 1;
    }
    strcpy(FileName,"s:\\");
    strcat(FileName,ReadText("pd.dat"));
    strcat(FileName,".txt");
    if(WriteData(FileName,Buffer))
    {
       clrscr();
       textbackground(0);
       textcolor(2);
       printf("Test Data Upload Succeed!!\n");
       return 0;
    }
    else
    {
        clrscr();
        textbackground(0);
        textcolor(4);
        printf("Test Data Upload Failed!!\n");
        return 1;
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值