鱼C论坛

 找回密码
 立即注册
楼主: 小甲鱼

[课后作业] S1E2:第一个程序 | 课后测试题及答案

    [复制链接]
发表于 2020-8-8 17:22:12 | 显示全部楼层
零基础入门学习C语言封面
《零基础入门学习C语言》
小甲鱼 著
立即购买
0000000
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-8 17:33:29 | 显示全部楼层
0.计算机cpu只懂二进制0与1
1机器语言/机器码(第一代编程语言)
2编译
3编译型,原代码直接转译为机器语言
  解释型语言,将原代码转为间接语言,通过解释器翻译给cpu
4不可以
5通过解释器转化为机器语言
6编译
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-8 18:41:43 | 显示全部楼层
1.只认识01  2.二进制 3.编译  4.进制不同  5.可以   6.不知道  7.电码  8.不知道
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-8 19:11:27 | 显示全部楼层

啊这

本帖最后由 Psycho.Z 于 2020-8-8 19:14 编辑

TIM图片20200808191357.png
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-8 20:24:25 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-8 20:28:14 | 显示全部楼层
da an
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-8 20:29:14 | 显示全部楼层
windows
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-8 23:30:11 | 显示全部楼层
感谢楼主
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-8 23:37:46 | 显示全部楼层
查看参考答案
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-9 00:05:17 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-9 10:15:26 | 显示全部楼层
1
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-9 13:43:37 | 显示全部楼层
第一次作业
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-9 14:09:07 | 显示全部楼层
0
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-9 15:09:48 | 显示全部楼层
111
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-9 15:27:31 | 显示全部楼层
我来看答案了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-9 21:01:38 | 显示全部楼层
#include <stdio.h>
#include <unistd.h>
#include <dirent.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>

#define MAX 256

long total;

int countlines(const char *filename);
int isCode(const char *filename);
void findALLDirs(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;
}

int isCode(const char *filename)
{
       int length;

       length = strlen(filename);

       if (!strcmp(filename + (length - 2), ".c"))
       {
              return 1;
       }
       else
       {
           return 0;
       }
}

void findALLDirs(const char *path)
{
    DIR *dp;
    struct dirent *entry;
    struct stat statbuf;

    if ((dp = opendir(path)) == NULL)
    {
        fprintf(stderr, "The path %s is wrong!\n",path);
        return;
    }

    chdir(path);
    while ((entry = readdir(dp)) != NULL)
    {
            lstat(entry->d_name, &statbuf);

            if(!strcmp(".", entry->d_name) || !strcmp("..", entry->d_name))
                continue;

            if (S_ISDIR(statbuf.st_mode))
            {
                   findALLDirs(entry->d_name);
            }
            else
            {
                   if (isCode(entry->d_name))
                   {
                         total += countlines(entry->d_name);
                   }
            }
    }

    chdir("..");
    clearerr(dp);
}

int main()
{
       char path[MAX] = ".";

       printf("计算中...\n");

       findALLDirs(path);

       printf("目前你总共写了 %ld 行代码!\n\n", total);

       return 0;
}
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-9 21:32:13 | 显示全部楼层
初学者报道!!!!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-9 21:34:35 | 显示全部楼层
瞧瞧
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-9 21:54:32 From FishC Mobile | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-9 22:53:32 | 显示全部楼层

  1. #include <io.h>
  2. #include <direct.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>

  6. #define MAX         256

  7. long total;

  8. int countLines(const char *fukename);
  9. void findAllCodes(const char *path);
  10. void findAllFiles(const char *path);

  11. int countLine(const char *filename)
  12. {
  13.         FILE *fp;
  14.         int count = 0;
  15.         int temp;
  16.        
  17.         if((fp = fopen(fukename), "r")) == NULL)
  18.         {
  19.                 fprintf(stderr, "Can not open the file:%s\n", filename);
  20.                 return 0;
  21.         }
  22.        
  23.         while ((temp = fgetc(fo)) !=EOF)
  24.         {
  25.                 if (temp =='\n')
  26.                 {
  27.                         count==;                       
  28.                 }
  29.         }
  30.        
  31.         fclose(fp);
  32.        
  33.         feturn count;
  34. }

  35. void findAllCodes(const char *path)
  36. {
  37.         struct _finddata_t fa;
  38.         long handle;
  39.         char thePath[MAX], target[MAX];
  40.        
  41.     strcpy(thePath, path);
  42.         if((handle = _findfirst(strcat(the Path, "/*.c"),&fa)) != -1L)
  43.         {
  44.                 do
  45.                 {
  46.                         sprintf(target, "%s%s", path, fa.name);
  47.                         total += countLines(target);
  48.                 }while (_findnext(handle, &fa) == 0);
  49.     }
  50.    
  51.     _findclose(handle);
  52. }

  53. void findAllDirs(const char *path)
  54. {
  55.         struct _finddata_t fa;
  56.         long handle;
  57.         char thePath[MAX];
  58.        
  59.         strcpy(thePath, path);
  60.         if((handle = _findfirst(strcat(thePath, "/*"),&fa)) == -1L)
  61.         {
  62.                 fprintf(stderr, "The path &s is wrong!\n",path);
  63.                 return;
  64.         }
  65.        
  66.         do
  67.         {
  68.                 if (!strcmp(fa.name, ".") || !strcmp(fa.name, "..") )
  69.                         continue;
  70.                         
  71.                         if( fa.attrib == _A_SUBDIR)
  72.                         {
  73.                                 sprintf(thePath, "%s/%s", path, fa.name);
  74.                                 findAllCodes(thePath);
  75.                                 findAllDirs(thePath);
  76.                                 }
  77.         }while (_findnext(handle, &fa) == 0);
  78.        
  79.         _findclose(handle);
  80. }

  81. int main()
  82. {
  83.         char path[MAX] = ".";
  84.        
  85.         printf("&#188;&#198;&#203;&#227;&#214;D...\n");
  86.        
  87.         findAllCodes(path);
  88.         findALLDirs(path);
  89.        
  90.         printf("&#196;&#191;&#199;°&#196;&#227;×ü12D′á&#203; %ld DD′ú&#194;&#235;! \n\n", total);
  91.         system("pause");
  92.        
  93.         return 0;       
  94. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-16 05:53

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表