ポータル・レポートの月次各省要約

6499 ワード

vi menhu_report.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define ROW 50
#define COLUMN 100

#define COUNT 31

int diff_province(char *all_province[COUNT],char now_province[ROW][COLUMN],int count) {
        int i,j;
        int mark;

        for(i=0;i<COUNT;i++) {
                int mark=0;

                for(j=0;j<count;j++) {
                        if(strcmp(all_province[i],now_province[j])==0) {
                                mark=1;
                                break;
                        }
                }

                if(mark==0)
                        printf("%s\t\t%d\t%d\t\t%d
",all_province[i],0,0,0); } return 0; } int main(int argc,char *argv[]) { char *p; FILE *fp; int i,ret,ret1,line=0; char readbuf[512]; char province[32],province_now[32]; int wap_num,client_new_num,client_old_num; int wap_num_now,client_new_num_now,client_old_num_now; int wap_num_all=0,client_new_num_all=0,client_old_num_all=0; int province_count=0; char *all_province[COUNT]={" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}; char now_province[ROW][COLUMN]; int j=0; if(argc==1) { fprintf(stderr,"input: %s file
",argv[0]); exit(-1); } fp=fopen(argv[1],"r"); if(fp==NULL) { fprintf(stderr,"fopen() %s error.
",argv[1]); exit(-1); } printf("province\twap\tclient_new\tclient_old
"); while(fgets(readbuf,512,fp)!=NULL) { i=0; line++; for(p=strtok(readbuf,"\t");p;p=strtok(NULL,"\t")) { i++; if(i==1) strcpy(province_now,p); if(i==4) wap_num_now=atoi(p); if(i==5) client_new_num_now=atoi(p); if(i==6) client_old_num_now=atoi(p); } // printf("%s,%d,%d,i=%d
",province_now,wap_num_now,client_num_now,i); if(strcmp(province,province_now)) { if(line==1) { strcpy(province,province_now); wap_num=wap_num_now; wap_num_all=wap_num_now; client_new_num=client_new_num_now; client_new_num_all=client_new_num_now; client_old_num=client_old_num_now; client_old_num_all=client_old_num_now; // continue; // province_count++; } else { printf("%s\t\t%d\t%d\t\t%d
",province,wap_num,client_new_num,client_old_num); wap_num=0; client_new_num=0; client_old_num=0; wap_num=wap_num_now; wap_num_all+=wap_num_now; client_new_num=client_new_num_now; client_new_num_all+=client_new_num_now; client_old_num=client_old_num_now; client_old_num_all+=client_old_num_now; } //// province_count++; if(line!=1) { strncpy(now_province[province_count++],province,strlen(province)); // printf("%s
",now_province[j++]); } } else { wap_num+=wap_num_now; wap_num_all+=wap_num_now; client_new_num+=client_new_num_now; client_new_num_all+=client_new_num_now; client_old_num+=client_old_num_now; client_old_num_all+=client_old_num_now; } strcpy(province,province_now); } // last province name strncpy(now_province[province_count++],province,strlen(province)); // printf("%s\t%d\t%d
",province,wap_num,client_num); printf("%s\t\t%d\t%d\t\t%d
",province,wap_num,client_new_num,client_old_num); ret1=diff_province(all_province,now_province,province_count); if(ret!=0) { fprintf(stderr,"diff_province() error.
"); } printf("all\t\t%d\t%d\t\t%d
",wap_num_all,client_new_num_all,client_old_num_all); ret=fclose(fp); if(ret==EOF) { fprintf(stderr,"fclose() error.
"); exit(-1); } printf("province_count=%d
",province_count); /* printf("----------------
"); for(j=0;j<province_count;j++) printf("%s
",now_province[j]); printf("----------------
"); */ exit(0); }