a837859225 发表于 2020-8-4 17:03:25

好好学习,天天向上

newbie1 发表于 2020-8-4 17:13:43

./test.c: line 10: long: command not found
./test.c: line 12: syntax error near unexpected token `('
./test.c: line 12: `int countLines(const char *filename);'
问下这是怎么了




这是第10到17行
long total;

int countLines(const char *filename);
int isCode(const char *filename);
void findAllDirs(const char *path);

int countLines(const char *filename)

JING_YING 发表于 2020-8-4 17:28:25

hi

白夜暮歌 发表于 2020-8-4 18:26:04

查看答案

阮阮沅 发表于 2020-8-4 18:30:13

看答案

cyl1994724 发表于 2020-8-4 18:32:23

111

978265615 发表于 2020-8-4 19:00:02

111

Tongyeah 发表于 2020-8-4 19:59:04

第一天打卡

浪里君莫笑 发表于 2020-8-4 20:07:10

打完了

浪里君莫笑 发表于 2020-8-4 20:08:46

小鱼为什么我只有九行

浪里君莫笑 发表于 2020-8-4 20:09:20


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

帅雷必成c王 发表于 2020-8-4 21:22:36

11

落樱语 发表于 2020-8-4 21:41:07

谢谢

glows. 发表于 2020-8-4 21:46:53

嗯嗯嗯嗯会了

750582899 发表于 2020-8-4 22:00:06


Mr`羽殇 发表于 2020-8-4 22:03:47

查看

shiningstar 发表于 2020-8-4 22:17:12

参考答案

小马小马 发表于 2020-8-4 22:19:26

+1

Mr`羽殇 发表于 2020-8-4 22:23:35

您好,我是Windows系统,为什么我动动手程序运行显示我打了11行代码。
之后我也试了将代码复制,然而还是11行代码。

ChiJoe 发表于 2020-8-4 22:35:11

1. 因为计算机只能识别机器语言
2. 机器语言
3. 编译
4. 编译型语言是将程序编译为汇编语言交由机器执行,而解释型语言通过解释器解释传达给机器
5. 解释型语言因为自带解释器所以可以跨平台运行,也可以在Windows平台运行
6. 摩斯密码的原理是双方约定一个密码本
7. 亲们 趁敌人吃饭时发动进攻
页: 789 790 791 792 793 794 795 796 797 798 [799] 800 801 802 803 804 805 806 807 808
查看完整版本: S1E2:第一个程序 | 课后测试题及答案