leo学电脑 发表于 2021-5-12 21:47:21

{:5_109:}

ZZQ0601 发表于 2021-5-12 22:46:11

激动的小手

q970869619 发表于 2021-5-12 23:48:25

验证答案

一一与11 发表于 2021-5-13 00:16:37

{:5_108:}

CR7LoveStudy 发表于 2021-5-13 09:13:11

D:\C语言\捕获.PNG

CR7LoveStudy 发表于 2021-5-13 09:14:38

CR7LoveStudy 发表于 2021-5-13 09:13


不能上传代码{:5_107:}
还有我在CentOS7上写了113行代码

whwh555 发表于 2021-5-13 10:07:59

1

海棠晃 发表于 2021-5-13 11:18:49

direct.h 不存在怎么办

457 发表于 2021-5-13 11:38:30

#include <stdio.h>
#include <unistd.h>
#include <dirent.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>

#define MAX 256

long total;

int countLines(const char *filename);
int isCode(const char *filename);
void findAllDirs(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;
}

int isCode(const char *filename)
{
      int length;

      length = strlen(filename);
      
      if (!strcmp(filename + (length - 2), ".c"))
      {
                return 1;
      }
      else
      {
                return 0;
      }
}

void findAllDirs(const char *path)
{
      DIR *dp;
      struct dirent *entry;
      struct stat statbuf;

      if ((dp = opendir(path)) == NULL)
      {
                fprintf(stderr, "The path %s is wrong!\n", path);
                return;
      }

      chdir(path);
      while ((entry = readdir(dp)) != NULL)
      {
                lstat(entry->d_name, &statbuf);

                if (!strcmp(".", entry->d_name) || !strcmp("..", entry->d_name))
                        continue;

                if (S_ISDIR(statbuf.st_mode))
                {
                        findAllDirs(entry->d_name);
                }
                else
                {
                        if (isCode(entry->d_name))
                        {
                              total += countLines(entry->d_name);
                        }
                }
      }

      chdir("..");
      closedir(dp);
}

int main()
{
      char path = ".";

      printf("计算中...\n");

      findAllDirs(path);

      printf("目前你总共写了 %ld 行代码!\n\n", total);

      return 0;
}




#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;
}

a-_- 发表于 2021-5-13 11:44:48

0.只认识二进制
1.机器语言
2.编译
3.不知
4、不能
5、

西瓜大仙 发表于 2021-5-13 13:06:03

11111

leli521 发表于 2021-5-13 13:06:55

2222

Boeing777-9x 发表于 2021-5-13 13:53:19

敲完发现C4996问题如何解决?想看答案

哀酱- 发表于 2021-5-13 14:51:45

1

卷王之王 发表于 2021-5-13 15:43:18

冲啊

khana 发表于 2021-5-13 18:28:30

冲冲冲

khana 发表于 2021-5-13 19:07:48

11

mollywcy 发表于 2021-5-13 20:36:05

day1

Zzq233 发表于 2021-5-13 21:21:24

1

qqletter 发表于 2021-5-13 21:32:24

收藏看看
页: 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 [1186] 1187 1188 1189 1190 1191 1192 1193 1194 1195
查看完整版本: S1E2:第一个程序 | 课后测试题及答案