wangjijia 发表于 2020-2-13 12:52:52

求救

C:\Users\Administrator\Desktop\test.c\第一堂课\collect2.exe        ld returned 1 exit status      我打完代码之后报错是这个,这个啥意思啊

一个账号 发表于 2020-2-13 13:03:28

把代码发上来

wangjijia 发表于 2020-2-13 13:13:59

一个账号 发表于 2020-2-13 13:03
把代码发上来

#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 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 findAIIDirs(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)
                {
                          Istat(entry->d_name,&statbuf);
                          
                          if (!strcmp(".",entry->d_name) || !strcmp("..", entry->d_name))
                                continue;
                                
                          if (S_ISDIR(statbuf.st_mode))
                          {
                                        findAIIDRES(entry->d_name);
                          }      
                          else
                          {
                     if (iscode(entry->d_name))
                                        {
                                                total += countLines(entry->d_name);       
                                           }                                 
                          }      
}

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

int main()
{
          char path = ".";
          
          printf("计算中...\n");
          
          findAIIDirs(path);
          
          print("目前你总共写了 %1d 行代码! \n\n", total);
          
          return 0;
}

zltzlt 发表于 2020-2-13 13:21:03

wangjijia 发表于 2020-2-13 13:13
#include
#include
#include


有许多地方抄错了……再认真检查一遍

一个账号 发表于 2020-2-13 13:23:49

wangjijia 发表于 2020-2-13 13:13
#include
#include
#include


你是 Mac 操作系统吗?

wangjijia 发表于 2020-2-13 13:31:33

一个账号 发表于 2020-2-13 13:23
你是 Mac 操作系统吗?

我是windows
那个Dev-c++

一个账号 发表于 2020-2-13 13:36:12

wangjijia 发表于 2020-2-13 13:31
我是windows
那个Dev-c++

你抄成 Mac OS 的了,代码应该是这样:

#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, target;
      
      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;
      
      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;
}
页: [1]
查看完整版本: 求救