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

  • Home
  • SEARCH
  • 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 8483943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:14:46+00:00 2026-06-10T20:14:46+00:00

I am very new with c and less experienced with any other language :/

  • 0

I am very new with c and less experienced with any other language :/
For an assignment at uni, I am a little stuck on this small part. Essentially I am required to write a ‘ls’ function that has 4 optional arguments, for example:

list [-l] [-f] [pathname] [localfile] 

Now, the first two are straight forward. To make things more difficult, the ‘localfile’ doesn’t necessarily exist and the ‘pathname'(if given) will be located on the server I’m connecting to through a socket (so checking if it is a file is out and checking the pathname is out). I was thinking, check last 4 chars in the string for a ‘.txt’ or something similar. I’m actually completely stumped and will present this problem to my course conveyor tomorrow, if I can’t find a solution.

This is a very small part of what I actually have to do but any push in the right direction would be appreciated.

  • 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-06-10T20:14:47+00:00Added an answer on June 10, 2026 at 8:14 pm

    You will need to process argc and argv to get your command line arguments. That is the first thing to work on, getting the arguments – ensuring they are correct, and determining what is being asked for.

    int main(int argc, char  *argv[])
    

    Assuming your are on Linux/Unix, you will need to use the directory functions opendir()/readdir()/closedir() – dirent.h. The stat() function will be required to satisfy the -l requirement. access() will determine if a file exists and then stat() will tell you if the file is a regular file or a directory.

    I’d make a struct to hold the four optional arguments and return it from a function called “process_arguments” that takes argc and argv as parameters.

    struct args {
      bool valid;
      bool l_option;
      bool f_option
      char directory[200]; 
      char filename[200];
    }
    

    With the requirement for a socket connection you will have to write a “server program” that will be constantly running on the server and a “client program” that it will fork to handle the requests from your local program. Try and locate examples of socket programs.

    Another check for whether you have a path string or a filename is to look for the path separator character – ‘/’ if the server is Unix/Linux. This scheme shouldn’t have any path separators in filenames, so the presence of one tells you it is a path.

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

Sidebar

Related Questions

Very new to python and can't understand why this isn't working. I have a
Im very new in C++ I have found this post http://msdn.microsoft.com/en-us/magazine/cc163486.aspx and trying to
I am very new to jQuery/JS and I have little problem with add or
I'm very new to Applescript but have used other scripting languages over the last
I'm very new to Grails. I have a table like this : +----+---------+----------------+----------------+-------------+--------------------+--------------+--------+---------------------+ |
I am very new to CSS, Bootstrap & LESS. I have checked out the
Very new to C++ and Cocos2d-x but I was just toying around with CCArray
Very new to javascript and html-type stuff. I wanted to just make a quick
Very new to FluentNHibernate, but I'm also excited about the area. I've recently started
Very new to JQuery and MVC and webdevelopment over all. I'm now trying to

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.