鱼C论坛

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

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

    [复制链接]
发表于 2018-8-13 00:10:42 | 显示全部楼层
谢谢甲鱼
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-13 09:44:15 | 显示全部楼层
看答案啦
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-13 10:58:25 | 显示全部楼层
fa未声明怎么办?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-13 14:50:37 | 显示全部楼层
0. 因为计算机只认识0和1
1. 机器语言
2. 忘了哈哈哈
3. 忘了。。
4. 不能
5. 通过不同的。。编码器?
6. 二进制
7. 不知道
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-13 16:58:42 | 显示全部楼层
打卡签到
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-13 16:59:13 | 显示全部楼层
0:二进制。0101
1.机器语言
2.编译
3.效率不同
4.不可以
5.不直接编码,而是转换为字节码,每次运行都要解释。
6.摩斯密码的原理就是查表。
7.亲们趁敌人吃法发动进攻
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-13 17:01:20 | 显示全部楼层
本帖最后由 AlexanderLeolin 于 2018-8-13 19:20 编辑

0:二进制。0101
1.机器语言
2.编译
3.效率不同
4.不可以
5.不直接编码,而是转换为字节码,每次运行都要解释。
6.摩斯密码的原理就是查表。
7.亲们趁敌人吃饭发动进攻
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-13 18:20:49 | 显示全部楼层
我复制代码上去为什么还是有一个错误。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-13 21:06:59 | 显示全部楼层
为啥计算出的是0行
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-13 21:35:38 | 显示全部楼层
想了解答案
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-14 16:17:53 | 显示全部楼层
#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[MAX],target[MAX];

        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[MAX];

        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[MAX] = ".";

        printf("计算中...\n");
       
        findAllCodes(path);
        findAllDirs(path);

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

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

使用道具 举报

发表于 2018-8-14 16:35:42 | 显示全部楼层
学习学习
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-14 22:10:47 | 显示全部楼层
小甲鱼牛逼
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-15 04:24:02 | 显示全部楼层
11111111111111
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-15 14:16:04 | 显示全部楼层
homework1.c:18:16: error: expected ';' at end of declaration
       FILE *fp
               ^
               ;
homework1.c:28:8: warning: implicit declaration of function 'While' is invalid
      in C99 [-Wimplicit-function-declaration]
       While ((temp = fgetc(fp)) != EOF)
       ^
homework1.c:28:41: error: expected ';' after expression
       While ((temp = fgetc(fp)) != EOF)
                                        ^
                                        ;
homework1.c:43:19: error: expected ';' at end of declaration
        int length
                  ^
                  ;
homework1.c:69:9: warning: implicit declaration of function 'chair' is invalid
      in C99 [-Wimplicit-function-declaration]
        chair(path)
        ^
homework1.c:69:20: error: expected ';' after expression
        chair(path)
                   ^
                   ;
homework1.c:94:1: error: function definition is not allowed here
{
^
homework1.c:104:2: error: expected '}'
}
^
homework1.c:58:1: note: to match this '{'
{
^
2 warnings and 6 errors generated.


不知道错哪里了。。。。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-15 14:45:08 | 显示全部楼层
沉迷学习2333 发表于 2018-8-15 14:16
homework1.c:18:16: error: expected ';' at end of declaration
       FILE *fp
               ^

改完了。。但是用的时候还有问题。。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-15 15:02:10 | 显示全部楼层
我想看一下答案
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-15 15:58:38 | 显示全部楼层
沉迷学习2333 发表于 2018-8-15 14:45
改完了。。但是用的时候还有问题。。

linker command failed with exit code 1 (use -v to see invocation)..老显示这个。。救命啊鱼大仙
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-15 16:42:16 | 显示全部楼层
就看一眼
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-15 16:59:29 | 显示全部楼层
那个统计代码函数的运行为啥显示“The Path . is wrong!”
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-16 00:27

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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