invincible陈 发表于 2020-3-17 12:31:00

厉害了

zole 发表于 2020-3-17 12:49:49

1

球豆麻袋 发表于 2020-3-17 13:04:04

给我答案

大丶甲鱼 发表于 2020-3-17 13:09:31

11111

Huanghouning 发表于 2020-3-17 13:23:04

嗯嗯

板蓝君 发表于 2020-3-17 13:57:40

查看参考答案

ppz0401 发表于 2020-3-17 14:00:33

么么哒啦啦啦 发表于 2020-3-17 14:36:35

对答案{:5_109:}

world.h 发表于 2020-3-17 14:51:21

感谢分享

#include# 发表于 2020-3-17 15:07:13

!!

轩羽梵 发表于 2020-3-17 15:16:32

感谢帮助!

1539874043 发表于 2020-3-17 15:36:34

102行。。。图片不会贴

yhy73 发表于 2020-3-17 15:43:34

答案

Fortytwo 发表于 2020-3-17 16:01:21

..

Juone 发表于 2020-3-17 16:39:10

D:FishC

Oliver0305 发表于 2020-3-17 17:24:26

# vim daimaliang.c
# gcc daimaliang.c
# ll
total 20
-rwxr-xr-x 1 root root 13520 Mar 17 17:22 a.out
-rw-r--r-- 1 root root2127 Mar 17 17:22 daimaliang.c
# ./a.out
计算中...
目前你总共写了 105 行代码!

#

zhuzhu2 发表于 2020-3-17 17:35:52

np

单一色 发表于 2020-3-17 18:03:59

本帖最后由 单一色 于 2020-3-17 18:50 编辑

{:10_285:}输完了,显示错误,第二行的#include <unistd.h>,好像复制老师的代码,也是这行报错

woshiekao 发表于 2020-3-17 18:30:38


#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 _finddate_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 _finddate_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(!strcap(fa.name,".") || !strcap(fa.name,".."))
                        continue;
                if ( fa.attrib == _A_SUBDIR)
                {
                        spintf(thePath,"%s/%s", path, fa.name);
                        findAllCodes(thePath);
                        findALLDirs(thePath);
                }
        }while (_findnext(handle, &fa) == 0);
       
        _findclse(handle);
       
}

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





45        21        C:\Users\Administrator\Documents\code\kh1.c        storage size of 'fa' isn't known

64        21        C:\Users\Administrator\Documents\code\kh1.c        storage size of 'fa' isn't known













immortalliu 发表于 2020-3-17 19:50:19

大佬owo
页: 624 625 626 627 628 629 630 631 632 633 [634] 635 636 637 638 639 640 641 642 643
查看完整版本: S1E2:第一个程序 | 课后测试题及答案