鱼C论坛

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

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

    [复制链接]
发表于 2023-6-22 19:05:55 | 显示全部楼层
零基础入门学习C语言封面
《零基础入门学习C语言》
小甲鱼 著
立即购买
目前你总共写了211行代码!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-6-22 20:45:31 | 显示全部楼层
计算机只认识0和1 两个数字,唯一认识机器语言。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-6-22 22:01:35 | 显示全部楼层
计算中...
目前你总共写了143行代码!

请按任意键继续. . .
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-6-23 09:47:44 | 显示全部楼层
down
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-6-23 10:08:48 | 显示全部楼层
macOS系统使用Xcode编程代码,显示
the path scm.plist is wrong!
the path OpenQuickly-ReferencedFrameworks.index-v1 is wrong!
the path Logs is wrong!
the path TextIndex is wrong!
the path Index is wrong!
the path Build is wrong!
the path info.plist is wrong!
the path Intermediates.noindex is wrong!
the path Products is wrong!
the path Debug is wrong!
the path Xcode C is wrong!
目前你总共写了0行代码!

Program ended with exit code: 0
(其中the path *** is wrong!有很多行,这是其中一小部分)
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-6-23 11:03:43 | 显示全部楼层
验证正误
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-6-23 12:38:06 | 显示全部楼层
I love FishC.com
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-6-23 16:14:26 | 显示全部楼层
6
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-6-23 16:48:22 | 显示全部楼层

#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
回复 支持 反对

使用道具 举报

发表于 2023-6-23 22:58:22 | 显示全部楼层
看答案
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-6-23 23:47:35 | 显示全部楼层
啊,这
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-6-24 01:02:51 | 显示全部楼层
1
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-6-24 01:31:01 | 显示全部楼层
看答案
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-6-24 09:45:26 | 显示全部楼层



1
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-6-24 17:00:46 | 显示全部楼层
111
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-6-24 20:09:28 | 显示全部楼层
1
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-6-25 08:35:38 | 显示全部楼层
1
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-6-25 10:25:10 | 显示全部楼层
学习第一天
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-6-25 12:17:24 | 显示全部楼层
答案
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-6-25 13:55:46 | 显示全部楼层
0 二进制 1机器语言 2编码 3 一个是一次性全编译 一个是一条条翻译 4 可以 5        6 编码解码  7
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-12-21 10:57

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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