It's UWAweek 48

help2002

This forum is provided to promote discussion amongst students enrolled in CITS2002 Systems Programming.
Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!"  followup message.

Displaying the 10 articles in this topic
Showing 10 of 919 articles.
Currently 3 other people reading this forum.


 UWA week 40 (2nd semester, week 10) ↓
SVG not supported

Login to reply

👍?
helpful
8:22pm Tue 4th Oct, ANONYMOUS

Hi Chris, Just a bunch of questions i would like to ask... 1) trovefile default is /tmp/trove -> is trove a folder or the actual file? if its the latter means if i were to make the default /tmp/trove.txt (for example since there is no restriction on the type of file) it would be legal? 2)I've been trying to understand how realpath() works but it seems to work provided that the relative path is in the same directory as the program (correct me if i am wrong). I am having difficulty trying to use this function to find files that are in different directories so some clarification would be great!! 3) is the trovefile input just the file name or it could be a path to the file? thank you!


SVG not supported

Login to reply

👍?
helpful
3:34am Wed 5th Oct, Christopher M.

ANONYMOUS wrote:
> 1) trovefile default is /tmp/trove -> is trove a folder or the actual file? if its the latter means if i were to make the default /tmp/trove.txt (for example since there is no restriction on the type of file) it would be legal?
(Any) trove-file is a *file*. The default trove-file is named "/tmp/trove". Any other name, such as "/tmp/trove.txt" is not the same name, and not the correct file.
> 2)I've been trying to understand how realpath() works but it seems to work provided that the relative path is in the same directory as the program (correct me if i am wrong). I am having difficulty trying to use this function to find files that are in different directories so some clarification would be great!!
#define _DEFAULT_SOURCE

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    char absolute_path[1024];

    realpath( ".", absolute_path );
    printf("%s\n", absolute_path);

    return 0;
}
> 3) is the trovefile input just the file name or it could be a path to the file?
If the trove-file is in the current directory you could use: ./trove -f my_trove_file .... or: ./trove -f ./my_trove_file .... or if it's somewhere else you could use: ./trove -f /User/me/cits2002/project2/my_trove_file ....


 UWA week 41 (2nd semester, week 11) ↓
SVG not supported

Login to reply

👍?
helpful
9:04pm Thu 13th Oct, ANONYMOUS

Hi Chris, I'm having some trouble successfully utilising realpath. I am using it as seen below: char absolutePath[1024]; realpath(<directory/file arg here (i.e. 'CITS2002')>, absolutePath); However if the directory/file that was provided is either above my current working directory (where my trove program is located) or in a subdirectory to it - the absolute path returned is incorrect For example, if my trove program is located in the directory: uni/CITS2002/Proj2 and I run: char absolutePath[1024]; realpath("CITS2002", absolutePath); I get the result of absolutePath = 'uni/CITS2002/Proj2/CITS2002' (which does not exist) I am using: #define _DEFAULT_SOURCE #include <stdio.h> #include <stdlib.h> #include <limits.h> Could you please provide some guidance on how to correctly use realpath for this situation? Would apreciate any help Thank you


SVG not supported

Login to reply

👍?
helpful
3:31am Fri 14th Oct, Christopher M.

ANONYMOUS wrote:
> I get the result of absolutePath = 'uni/CITS2002/Proj2/CITS2002' (which does not exist)
I can replicate this on both macOS and Linux. Suggest that you check the return result from realpath() :
#define _DEFAULT_SOURCE

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

int main(int argc, char *argv[])
{
    char absolute_path[1024];

    if(realpath( "CITS2002", absolute_path ) == NULL) {
        perror("CITS2002");
        exit(EXIT_FAILURE);
    }

    printf("%s\n", absolute_path);
    return 0;
}


SVG not supported

Login to reply

👍?
helpful
9:16am Fri 14th Oct, ANONYMOUS

Hey Chris, Thanks, the return result from realpath is NULL which is correct. I think I confused myself as I've been trying to find absolute pathnames for files/directories located above the current working directory (i.e looking for "CITS2002" from within the directory uni/CITS2002/Proj2). "CITS2002" exists, but not within "Proj2". I understand we must find the requested file/directory (if it exists) and traverse all its subdirectories recursively. Can I please confirm if we are required to find files/directories which are not located within the current working directory (or subdirectories of the current working directory)? Should attempting to do so report an error such as "file/directory not found" (indicated by NULL being returned by realpath)? Thanks again for the help!


SVG not supported

Login to reply

👍?
helpful
9:18am Fri 14th Oct, Christopher M.

ANONYMOUS wrote:
> Can I please confirm if we are required to find files/directories which are not located within the current working directory (or subdirectories of the current working directory)?
Via the command-line you may be asked to index files from anywhere. They could be 'local', absolute, or relative to where you are.


SVG not supported

Login to reply

👍?
helpful
10:43am Fri 14th Oct, ANONYMOUS

Hi Chris, Can I please clarify the below? Absolute file/directories - will this be a fully complete absolute pathname? i.e. "CITS2002" as in the example above would be expected to fail (as it does not exist relative to the working directory), but "<path>/uni/CITS2002" should be successful (given it exists at that location)? Thanks again!


SVG not supported

Login to reply

👍?
helpful
1:52pm Fri 14th Oct, Christopher M.

ANONYMOUS wrote:
> Absolute file/directories - will this be a fully complete absolute pathname?
I am unsure why this has become so convoluted. By its very definition, an absolute pathname, whether it refers to a directory or a file, whether that named directory name or that named file exists, simply begins with a '/'.


SVG not supported

Login to reply

👍?
helpful
7:08pm Sat 15th Oct, ANONYMOUS

How can you name a file with "/"? When I go to name a file on my desktop to be include a "/" it says "file names cannot contain "/"". Is the /tmp/trove refering to creating a temporary file?


SVG not supported

Login to reply

👍?
helpful
5:25am Sun 16th Oct, Christopher M.

ANONYMOUS wrote:
> How can you name a file with "/"? When I go to name a file on my desktop to be include a "/" it says "file names cannot contain "/"". Is the /tmp/trove refering to creating a temporary file?
The names of files - filenames - cannot contain the '/' character or the \0 character. The '/' character separates the components of a pathname, such as "dir1/dir2/dir3/file1". As a special case, the pathname "/" refers to the root-directory of a file-system. The \0 character is used to terminate a string that is passed to a system-call, such as open(), creat(), unlink(), ...

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Written by [email protected]
Powered by history
Feedback always welcome - it makes our software better!
Last modified  1:17AM Sep 14 2022
Privacy policy