Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6874055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:08:49+00:00 2026-05-27T04:08:49+00:00

I’ve got a little problem with an exercise I have to finish. We have

  • 0

I’ve got a little problem with an exercise I have to finish. We have to implement a recurisve “ls” program which prints out the “n” biggest files. But there are some problems.

1)

I have three files, main.c, list.c and list.h. In list.h I have included string.h ,stdio.h,stdlib.h,declared a struct (char* filename,long long filesize and struct element* next) and two methods (append,printlist). In list.c I have included list.h and implemented the two methods append and printlist. In main.c I have included unistd.h,dirent.h, sys/stat.h and list.h.

When I try to compile it with “gcc main.c” I get the error “used of undeclared methods append and printlist” but if I’m using Eclipse it builds just fine. How can I solve this?

Exact errors

/tmp/ccLbHnqR.o: In function `main':
main.c:(.text+0x189): undefined reference to `printliste'
/tmp/ccLbHnqR.o: In function `ftop':
main.c:(.text+0x1f6): undefined reference to `append'

2)

To implement the functionality I tried to use a self-sorting list, i.e. go through the list until the last value that is bigger than the new value, then set the pointer of the new value to the pointer of the last value and the pointer of the last value is the new value.

In theory it should work, but in practice it isn’t.

The append methods looks like this

void append(struct element **lst, char* filename, long long filesize){
    struct element *newElement;
    struct element *lst_iter = *lst;

    newElement = malloc(sizeof(*newElement)); // create new element
    newElement->filename = filename;
    newElement->filesize = filesize;
    newElement->next = NULL; // important to find the end of the list

    if ( lst_iter != NULL ) { // if elements are existing
        //if our element is bigger than the first element
        if(lst_iter->filesize < newElement->filesize){
            newElement->next = lst_iter;
            *lst = newElement;
        } else {
            while(lst_iter->next != NULL){
                if(lst_iter->filesize > newElement->filesize) lst_iter = lst_iter->next;
                else break;
            }
            newElement->next = lst_iter->next;
            lst_iter->next = newElement;
        }           
    }
    else // if the list is empty our value is the new value
    *lst=newElement;
}

I’m using this method from my “ftop” method, which gets a directory, adds every file in this directory to the list and for each directory it calls “ftop” again.

void ftop(char* path){
    DIR *dir;
    struct dirent *ent;

    //open the directory
    dir = opendir(path);
    if (dir != NULL) {
        //for each file/directory in it
        while ((ent = readdir(dir)) != NULL) {
            struct stat st;
            //if it is a file, append it to the list
            if(S_ISREG(st.st_mode)){
                append(&list, ent->d_name, st.st_size);
            } else {
                //if it is a directory, use recursion
                ftop(ent->d_name);
            }
        }
    }
}

But I don’t get it why it isn’t working. I know you don’t want to do the homework of others, but I would be thankful for every hint you could give me.

P.s.: If you want the full code

main.c
list.c

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:08:50+00:00Added an answer on May 27, 2026 at 4:08 am

    You want

    gcc -o main main.c list.c
    

    that is — specify both files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.