河南理工CXP 发表于 2021-1-30 10:22:38

回复

张洪玮 发表于 2021-1-30 11:42:10

C:\Users\gujia\Desktop

半醉半醒之间 发表于 2021-1-30 12:28:04

作业已完成,需对答案

Q梓垚 发表于 2021-1-30 12:48:15

目前你总共写了0行代码

灵均正泽 发表于 2021-1-30 13:44:24

答案?

chenzeyang_424 发表于 2021-1-30 14:43:13

查看答案

滴滴10086 发表于 2021-1-30 15:40:51

0.质能读懂二进制语言
1.机器语言
2.编译
3.速度快,不需要翻译
4.可以
5.
6.二进制

maohaha0625 发表于 2021-1-30 15:48:32

ok

踏月色行凶 发表于 2021-1-30 16:02:08

1

神之都根特 发表于 2021-1-30 16:40:34

跟着小甲鱼真的学到了很多

sakura-wss 发表于 2021-1-30 16:41:27

学完啦

氨基酸LOVE 发表于 2021-1-30 16:44:57

查看答案

清风一样的人 发表于 2021-1-30 16:55:50

答案

小与森 发表于 2021-1-30 17:14:12


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

森森森森森 发表于 2021-1-30 17:59:40

。。出了点问题

沉默的小小人 发表于 2021-1-30 18:04:43

{:5_103:}

lenghanbingchao 发表于 2021-1-30 18:07:35

自己写的报这个错:1 duplicate symbol for architecture x86_64

毁的湖光 发表于 2021-1-30 18:09:07


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

a1960213242 发表于 2021-1-30 18:20:04

我真的已经自己做完了

aandbcct 发表于 2021-1-30 19:11:24

页: 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 [1044] 1045 1046 1047 1048 1049 1050 1051 1052 1053
查看完整版本: S1E2:第一个程序 | 课后测试题及答案