不得不 发表于 2022-8-18 23:35:26

查看参考答案

tiantang_8 发表于 2022-8-18 23:41:56

看看答案

iassassint 发表于 2022-8-19 07:51:32

11111111

爱喝水的彼得 发表于 2022-8-19 09:11:53

无法打开源文件:字符串

徐榕槟 发表于 2022-8-19 10:38:22

{:10_277:}

zzzix16 发表于 2022-8-19 11:29:28

666

yzak 发表于 2022-8-19 11:47:20

太难了,我直接复制粘贴

xiaomengxin1 发表于 2022-8-19 11:59:28

.

春风随我狮鸣 发表于 2022-8-19 12:08:08

吼吼吼

Anmelis 发表于 2022-8-19 13:03:18

$ gcc count_lines.c -o count_lines
$ ./count_lines
计算中...
目前你总共写了 105 行代码!

$

tinjoe 发表于 2022-8-19 13:36:42

照抄谁不会!

Type-3 发表于 2022-8-19 16:27:35

1

奇迹观测 发表于 2022-8-19 16:27:38

1

LongerSking 发表于 2022-8-19 20:11:18


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

#define max 256

;

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

int countLines(const char *filename)
{
File *fp;
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;
长手柄;
char thePath, target;
      
strcpy(thePath, path);
if((handle = _findfirst(strcat(thePath, "/*.c"), &fa)) != -1L)
      {

                {
sprintf(target, “%s/%s”, path, fa.name);
sum += count线(目标);
}while (_findnext(handle, &fa) == 0);
      }
   
_findclose(手柄);
}

void findALLDirs(const char *path)
{
结构_finddata_t法;
长手柄;
char thePath;
      
strcpy(thePath, path);
if((handle = _findfirst(strcat(thePath, “/*”), &fa)) == -1L)
      {
fprintf(stderr, “path %s is error!\n”,path);
return;
      }
   

      {      
if (!strcmp(fa.name, “.”) || !strcmp(fa.name, “..”))
继续;
                  
if( fa.attrib == _A_SUBDIR)
                {      
sprintf(thePath, “%s/%s”, path, fa.name);
findAllCodes(thePath);
findALLDirs(thePath);
                }
}while (_findnext(handle, &fa) == 0);
   
_findclose(手柄);
}

int main()
{
字符路径 = “.”;
      
printf(“计算中...\n”);
      
findAllCodes(path);
findALLDirs(path);
      
printf(“目前你总共写了 %ld 行代码!\n\n”, total);
stream(“暂停”);
      
return 0;
}

Chenzyishere 发表于 2022-8-19 20:17:54

太厉害啦

12465 发表于 2022-8-19 20:36:08

1

f041115 发表于 2022-8-19 22:45:19

333

好好爱学习abo 发表于 2022-8-19 22:50:04

看看答案

batterie 发表于 2022-8-20 00:45:32

来对答案了

萌新围观大佬 发表于 2022-8-20 09:53:32

报错
页: 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 [1710] 1711 1712 1713 1714 1715 1716 1717 1718 1719
查看完整版本: S1E2:第一个程序 | 课后测试题及答案