羊的世界 发表于 2020-10-21 06:49:59

{:5_109:}

北岸z 发表于 2020-10-21 08:29:03

请问为什么我运行完这个程序之后,之后运行其他程序比如Hello World 弹出来的也是这个“目前你总共写了...行代码”

阿贝学c呀 发表于 2020-10-21 09:39:47

1机器语言
2编译
3不知道
480%可以

GNAF 发表于 2020-10-21 10:25:34

3岁的程序员 发表于 2020-10-21 10:29:46

666

Ninsko 发表于 2020-10-21 12:33:09

为啥运行出错

又鸟巴子 发表于 2020-10-21 14:00:35

1

蝙蝠侠666 发表于 2020-10-21 14:49:10

抄完啦

詹胜人 发表于 2020-10-21 14:49:35

答案

Acherk 发表于 2020-10-21 15:09:37

yep

a123456897 发表于 2020-10-21 15:31:59

1

凤皇 发表于 2020-10-21 15:32:26

.

玉带林中挂 发表于 2020-10-21 15:54:07


#include <io.h>
#include <direct.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX      256

long total;

int countLines(const char *filename);
void findAllCodes(const char *path);
void findALLFiles(const char *path);

int countLines(const char *filename)
{
      FILE *fp;
      int count = 0;
      int temp;
      
      if ((fp = fopen(filename, "r")) == NULL)
      {
                fprintf(stderr, "Can not open the file:%s\n", filename);
                return 0;
      }
      
      while ((temp = fgetc(fp)) != EOF)
      {
                if (temp == '\n')
                {
                        count++;
                }
      }
      
      fclose(fp);
      
      return count;
}

void findAllCodes(const char *path)
{
      struct _finddata_t fa;
      long handle;
      char thePath, target;
      
      strcpy(thePath, path);
      if((handle = _findfirst(strcat(thePath, "/*.c"), &fa)) != -1L)
      {
                do
                {
                        sprintf(target, "%s/%s", path, fa.name);
                        total += countLines(target);
                }while (_findnext(handle, &fa) == 0);
      }
   
      _findclose(handle);
}

void findALLDirs(const char *path)
{
      struct _finddata_t fa;
      long handle;
      char thePath;
      
      strcpy(thePath, path);
      if((handle = _findfirst(strcat(thePath, "/*"), &fa)) == -1L)
      {
                fprintf(stderr, "The path %s is wrong!\n",path);
                return;
      }
   
      do
      {      
                if (!strcmp(fa.name, ".") || !strcmp(fa.name, ".."))
                        continue;
                  
                if( fa.attrib == _A_SUBDIR)
                {      
                        sprintf(thePath, "%s/%s", path, fa.name);
                        findAllCodes(thePath);
                        findALLDirs(thePath);
                }
      }while (_findnext(handle, &fa) == 0);
   
      _findclose(handle);   
}

int main()
{
      char path = ".";
      
      printf("计算中...\n");
      
      findAllCodes(path);
      findALLDirs(path);
      
      printf("目前你总共写了 %ld 行代码!\n\n", total);
      system("pause");
      
      return 0;
}

scaredsss 发表于 2020-10-21 16:13:42

666666666666666666666

DearApollo 发表于 2020-10-21 17:01:05

1

TTT12345 发表于 2020-10-21 17:31:32

1

波波3 发表于 2020-10-21 17:57:10

..

huliaohaha 发表于 2020-10-21 18:08:17

haha

熙沫颜cys 发表于 2020-10-21 18:25:06

嗯?

a残梦 发表于 2020-10-21 18:30:03

终于好了
页: 906 907 908 909 910 911 912 913 914 915 [916] 917 918 919 920 921 922 923 924 925
查看完整版本: S1E2:第一个程序 | 课后测试题及答案