zoukankan      html  css  js  c++  java
  • 又一个小程序

    想让自己轻松一点,就要让PC多为你做点。

    还是一个方便自己,提高工作效率的程序。

    主要实现几个功能:

    1.查看目录

    2.查看数据

    3.查看网页

    View Code 
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    int main()
    {
        char dir_in[100]="dir D:\\data\\0000\\ | find \".in\" /I";
        char dir_out[100]="dir D:\\data\\0000\\ | find \".out\" /I";
        char path_in[100]="D:\\data\\0000\\data1.in";
        char path_out[100]="D:\\data\\0000\\data1.out";
        char IE[200]="start d:\\小工具\\ie.lnk http://acm.sdut.edu.cn/web/problem.php?action=showproblem^&problemid=0000";
        char kill_IE[]="taskkill /f /t /im iexplore.exe > nul";
        char err_problem[]="d:\\小工具\\err_problem.txt";
        int num,i=0;
        system("mode con cols=80 lines=50");
        printf("\t\t检查题目专用程序  <ma6174>\n\n");
        printf("输入要查看目录的起始号码:");
        scanf("%d",&num);
        if(num<1000||num>10000)
        {
             printf("输入错误\n");
             getch();
             exit(1);
        }
        while(1)
        {
             char num_c[4];
             itoa(num,num_c,10);
             for(i=0;i<4;i++)
             {
                  dir_in[12+i]=dir_out[12+i]=num_c[i];
                  path_in[8+i]=path_out[8+i]=num_c[i];
                  IE[92+i]=num_c[i];
             }
             system(IE);
             printf("------------------------%d----------------------------------------\n",num);
             system(dir_in);
             system(dir_out);
             for(i=1;i<70;i++)
             printf("-");
             printf("\n");
             char ch;
             while(1)
             {
                  FILE *fp;
                  fp=fopen(path_in,"rt");
                  if(fp==NULL)
                  {
                      printf("文件打开失败!\n");
                      printf("\n按任意键查看下一个题目\n");
                      getch();
                      num++;
                      break;
                  }
                  printf("data%c.in文件的内容:(只显示前15行)\n",path_in[17]);
                  int count=15;
                  ch=getc(fp);
                  while(count&&ch!=EOF&&fp!=NULL)
                  {
                       if(ch=='\n')
                             count--;
                       printf("%c",ch);
                       ch=getc(fp);
                  }
                  printf("\n");
                  for(i=1;i<70;i++)
                  printf("-");
                  printf("\n");
                  printf("<空格>继续查看    <n>下一个data.in文件    <o>查看输出文件\n");
                  printf("<回车>下一个题    <s> 保存有问题的题目\n"); 
                  for(i=1;i<70;i++)
                  printf("-");
                  printf("\n");
                  ch=getch();
                  if(ch==' ')
                  {
                       count=15;
                       ch=getc(fp);
                       while(count&&ch!=EOF&&fp!=NULL)
                       {
                                 if(ch=='\n')
                                        count--;
                            printf("%c",ch);
                            ch=getc(fp);
                       }
                       printf("按任意键查看下一个题目\n");
                       getch();
                  }
                  fclose(fp);
                  if(ch=='n'||ch=='N'&&path_in[17]<='8')
                  {
                       printf("\n\n\n");
                       path_in[17]++;
                       continue;
                  }
                  if(ch=='s'||ch=='S')
                  {
                       fp=fopen(err_problem,"at");
                       if(fp==NULL)
                       {
                            printf("d:\\小工具\\err_problem.txt 打开失败!\n");
                            getch();
                            exit(1);
                       }
                       fprintf(fp,"%d\n",num);
                       fclose(fp);
                       printf("有问题的题目已经记录在d:\\小工具\\err_problem.txt\n");
                       printf("\n按任意键查看下一个题目.....\n");
                       getch(); 
                       break;
                  }
                  if(ch=='o'||ch=='O'||ch=='0')
                  {
                       fp=fopen(path_out,"rt");
                       if(fp==NULL)
                       {
                            printf("文件打开失败!\n");
                            printf("\n按任意键查看下一个题目......\n");
                            getch();
                            break;
                       }
                       printf("data%c.out文件的内容:\n",path_out[17]);
                       int count=15;
                       ch=getc(fp);
                       while(count&&ch!=EOF&&fp!=NULL)
                       {
                            if(ch=='\n')
                                count--;
                            printf("%c",ch);
                            ch=getc(fp);
                       }
                       fclose(fp);
                       printf("\n按任意键查看下一个题目......\n");
                       getch();
                    } 
                    break;
             }
             path_in[17]=path_out[17]='1';
             system("cls");
             system(kill_IE);
             num++;
        }

    程序的优点就不说了,你也用不到,主要说说在编程中遇到的几个小问题,或许大家以后编程也会遇到

    1.关于dos命令问题,因为在dos中,有些特殊符号,比如&,>,<,|,等都有特殊功能,如果命令中只是作为一个字符的话,要在前面加上 ^ 符号

    2.dos中如果目录名中间有空格的话就要加双引号,但是如果双引号里面还嵌套双引号的话就有问题了,这时可以将有空格的目录文件建立一个快捷方式,将快捷方式放到一个目录名没有空格的文件夹里面,打开快捷方式和打开原文件是同样的效果。

    3.文件复制时需要读取文件,最好用ch=getc(fp)这种方式一个字符一个字符地读取,然后再写文件的时候就会保留原来文件的格式 

      经典的文件复制代码:

    for(ch=getc(inp);ch!=EOF;ch=getc(inp))

        putc(ch,outp); 

    程序的问题:

    毕竟学的知识有限,如果会数据库编程的话我就可以直接从数据库中读取我想要的内容,就不用打开网页了;如果会建立多个窗口的话我就可以在一个界面中分三个窗口,一个是文件列表,一个是文件内容,一个是数据库数据,这样查看起来更简单。

    现在了解的知识还是太少,不能在无聊的事情上浪费时间了,抓紧时间学习新知识,新技能,多学点知识总是好的,说不定什么时候就能用到。


    博主ma6174对本博客文章(除转载的)享有版权,未经许可不得用于商业用途。转载请注明出处http://www.cnblogs.com/ma6174/

    对文章有啥看法或建议,可以评论或发电子邮件到ma6174@163.com


  • 相关阅读:
    MongodDB数据库安装和简单使用
    比较运算符
    Java习题
    JavaScript示例
    Java面向过程练习题7
    Java面向过程练习题6
    倒金字塔
    包含contains
    String 比较
    单词表
  • 原文地址:https://www.cnblogs.com/ma6174/p/2352208.html
Copyright © 2011-2022 走看看