于洪琪 发表于 2018-11-9 18:40:25

哈哈楼,三克油

狸刃 发表于 2018-11-9 21:09:44

代码抄错了,不知道错在什么地方

SNADO 发表于 2018-11-9 21:35:18

哇 来看看

wp19991 发表于 2018-11-10 01:46:14

123

嘎嘎尕尕 发表于 2018-11-10 10:14:44

亲们

飞行叶子 发表于 2018-11-10 11:12:37

||=== 构建文件: "无目标" 在 "无项目" 中 (编译器: 未知的) ===|
E:\C学习\入门1\main.c||In function 'countLines':|
E:\C学习\入门1\main.c|24|warning: implicit declaration of function 'fpintf' [-Wimplicit-function-declaration]|
E:\C学习\入门1\main.o:main.c|| undefined reference to `fpintf'|
||error: ld returned 1 exit status|
||=== 构建 失败: 2个错误, 1个警告 (0 分, 1 秒) ===|

Karakaka 发表于 2018-11-10 11:28:08

0

飞行叶子 发表于 2018-11-10 11:50:40

本帖最后由 飞行叶子 于 2018-11-10 11:51 编辑

计算中...
Can not open the file: .main.c
The path .bin is wrong!
The path .obj is wrong!
目前你总共写了 0 行代码!

请按任意键继续. . .

打印后是这个结果,对了好几遍,没找出问题,麻烦老师指点下!感谢


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

#define MAX256

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 thePth,target;

    strcpy(thePth, path);
    if((handle =_findfirst(strcat(thePth,"/*.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;
}

zsmybwn 发表于 2018-11-10 12:46:45

看看

淡然然 发表于 2018-11-10 13:49:21

答案是啥丫

lxwlxxoo1 发表于 2018-11-10 19:19:27

学习学习学习好

看到让你流口水 发表于 2018-11-10 22:38:50

厉害

H-Lite 发表于 2018-11-11 10:09:57

看看我的答案对不对

dongfeng725 发表于 2018-11-11 17:54:19

这个会按时间记录所有的?如果是在这个程序之前写的他就不记录了?

小天天天 发表于 2018-11-11 19:51:35

答案

s838490 发表于 2018-11-11 20:28:30

0

autocad 发表于 2018-11-11 20:49:16

nice

空城追dream 发表于 2018-11-11 23:40:27

谢谢

豫南明珠 发表于 2018-11-12 00:29:59

查看答案

AINR 发表于 2018-11-12 09:53:57

答案
页: 194 195 196 197 198 199 200 201 202 203 [204] 205 206 207 208 209 210 211 212 213
查看完整版本: S1E2:第一个程序 | 课后测试题及答案