hanjingmin0805 发表于 2021-11-29 20:20:13

1

加油学好c 发表于 2021-11-29 20:35:29

yaodaan aaa

HJTIAO 发表于 2021-11-29 20:57:57

{:5_102:}

linuxe 发表于 2021-11-29 21:27:08


#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)
                {
                        fprint(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);
                                                findALLSirs(thePath);
                                       
                                }
                }while(_findnext(handle,&fa) == 0);
               
                _findclose(handle);
       
}

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

LSliu603 发表于 2021-11-29 21:51:22

{:5_108:}

lodetion 发表于 2021-11-29 22:36:20

趴在桌上检查了一个小时,总算是检查出来问题了,原来是findALLDirs函数里面的if语句少打了一个括号,擦擦擦擦擦
而且好像还第一次改过之后没有保存,第二次整个检查的时候再次翻到那里发现没改过来,我擦擦啊,
总算是OK了,哇哇哇,这种成就感,实在是太爽了啊、
爽爽爽

Tarf 发表于 2021-11-29 22:55:01

鱼哥,请教个问题。win10下VSCode运行代码(多少行代码那个)出现了问题。分别尝试了自己手打代码和直接复制源码两种方法,均无法运行。都是中文乱码。璁$畻涓

dumdum 发表于 2021-11-29 23:21:41

好诶

澹烟LR 发表于 2021-11-29 23:42:57

看看

澹烟LR 发表于 2021-11-30 00:03:06

求教,为啥我打出来的代码只显示总共写了7行代码?把题目上的代码复制进去也是7行。

离木·笑语山河 发表于 2021-11-30 00:42:53

0.因为他只能识别二进制的机器语言
1.机器语言
2.编译
3.编译型通过编译直接将程序语言转换成机器语言,而解释型语言需要解释器
4.不可以
5.使用高级程序语言
6.0和1
7.不清楚

learner2020 发表于 2021-11-30 01:13:16

1

周杰轮胎 发表于 2021-11-30 10:05:30

谢谢

Devil1024 发表于 2021-11-30 10:16:55

C:\Users\Ron\Desktop\fishc\s1e2\s1e2

hnlxx 发表于 2021-11-30 10:18:17

看下对了几个。。

陈白露 发表于 2021-11-30 10:53:05

我好久没逛论坛了!新人报到第一天!

1282283833 发表于 2021-11-30 13:56:59

朕想知道

前来学习一下 发表于 2021-11-30 15:13:25

零零零零

缪炜东 发表于 2021-11-30 15:49:39

谢谢了

我是程序员02号 发表于 2021-11-30 16:07:54

呜呜呜
页: 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 [1475] 1476 1477 1478 1479 1480 1481 1482 1483 1484
查看完整版本: S1E2:第一个程序 | 课后测试题及答案