曾开心i 发表于 2020-4-22 01:42:58

0.计算机只懂二进制
1.机器码
2.编译
3.是否需要解释器
4.可以
5.通过解释器
6.查表,解码
7

5huiwen 发表于 2020-4-22 02:38:37

回复

Stefan_Yang 发表于 2020-4-22 08:34:31

111

我不是山谷 发表于 2020-4-22 08:41:43

1

2889495843 发表于 2020-4-22 10:55:32

我来了,鱼

淮竹 发表于 2020-4-22 11:09:02

66

Tiehanhank 发表于 2020-4-22 12:05:09

本帖最后由 Tiehanhank 于 2020-4-22 12:08 编辑

#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("..");
      closedir(dp);
}

int main()
{
      char path = ".";

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

      findAllDirs(path);

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

      return 0;
}





哪里错了呜呜呜
结果如下:
计算中......
The path . is wrong!
The path s1e2 is wrong!
Can not open the file: count_lines.c
Can not open the file: count_lines.c
The path .DS_Store is wrong!
The path s1e2 is wrong!
The path count_lines is wrong!
The path count_lines.c is wrong!
The path a.out is wrong!
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
Can not open the file: count_lines.c
目前你总共写了 0 行代码!


一瓶 发表于 2020-4-22 12:37:28

查看

好逑 发表于 2020-4-22 13:50:41


#include<io.h>
#include<direct.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define MAX   256

long total;

int countlines(const char *fliename);
void findallcodes(const char *path);
void findallfiles(const char *parth);

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+=countlinrs(target);
               }while(_findnext(handle,&fa)==0)
       }
}
void findalldirs(cont char *path)
{
        struct_finddata_t fa;
        long handle;
        char thepath;
       
        strcpy(thepath,path);
        if((handle=_findfirst(strcat(thepath,"/*"),&fa))=-1L)
        {
                fprintf
          }
          
          do
          {
                  if(!strcmp(fa.name,".")||!strcmp(fa.name,".."))
                  continue;
                 
                  if(fs.attri==_A_SUBDIR)
                  {
                          sprintf(thepath,"%s/%s",path,fa.name);
                          findallcodes(thepath);
                          findalldirs(thepath);
                  }
          }whule(_findclose(handle,&fa)==0);
          
          _findclose(handle);       
}

int main9
{
        char path=".";
       
        printf("计算中...\n");
       
        findallcodes(path);
        findalldirs(path);
       
        printf("目前你总共写了%ld行代码!\n\n",total) ;
        system("pasue");
       
        return 0;
}

swpuzrs 发表于 2020-4-22 13:52:41

查看答案

yuchiyuchiyu 发表于 2020-4-22 14:36:38

0、因为计算机只能读懂0和1
1、机器语言
2、编译
3、编译型语言直接编译比较灵活、解释型语言还需要解释器
4、能
5、解释型编程语言执行时需要解释器
6、原理是编译,将密码按照表翻译成能读懂的语言
7、

wdnmd1ccc 发表于 2020-4-22 15:05:29

修改

960825620 发表于 2020-4-22 16:07:43

0.只认识二进制
1.机器语言
2.编译
3.解释型语言可跨平台
4.不能
5.例如Java就有jvm包可实现跨平台
6.二进制码

笑我痴 发表于 2020-4-22 16:44:31

9999999999

Asagiri_Mai 发表于 2020-4-22 17:01:03

109行代码

Yusenchen 发表于 2020-4-22 17:16:45

liandom 发表于 2020-4-22 17:21:52

看看答案

未希 发表于 2020-4-22 17:49:54

0,
1,机器语言
2,编译
3,能否直接编译成机器码
4,不能
5,将源码转换成中间代码,然后发送给解释器,由解释器逐句翻译给 CPU
6,查表
7,亲们,趁敌人吃饭时发动进攻

王麒 发表于 2020-4-22 19:07:49

0.        因为计算机只认识二进制代码
1.        编程语言
2.        编译
3.        解释型语言需要解释器,编译型语言不需要
4.        是
5.        需要解释器
6.        查表

FCBarcelona 发表于 2020-4-22 20:02:10

页: 671 672 673 674 675 676 677 678 679 680 [681] 682 683 684 685 686 687 688 689 690
查看完整版本: S1E2:第一个程序 | 课后测试题及答案