It's UWAweek 48


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 selected article
Showing 1 of 919 articles.
Currently 3 other people reading this forum.

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

Login to reply

7:48am Sat 6th Aug, Christopher M.

"Haoxuan Long" <23*4*1*[email protected]*u*e*t*u*a*e*u*a*> wrote:
> I need some help with question 10, specifically need help with c deciding whether my file is the name of a text file or an user input text. > few lines of my code: > > FILE *fp; > //there is a text file "text.txt" located in the follow folder > fp = fopen("/mnt/c/Users/argvalue[1]", "r+"); > > > the output is "no such file or directory, segmentation fault" when i input the command line argument of text.txt, I must specify the name of file by replacing argvalue[1] with "text.txt"in the code for the text to be read and ciphered. > > But if I do change argvalue[1] into text.txt, when I have a command line input, the code will cipher text.txt regardless so I don't want that either. Thought I might need some kind of isdigit checking function but for files, but i can't find that on the internet.
You do not need to prefix each filename with its (assumed) directory. Just try to open the required filename, and if the user wishes to open a file located in another directory, then they will provide the required directory and file name themselves: fp = fopen( argvalue[1], "r" ); The fopen() function indicates success or failure by returning a non-NULL or NULL value, respectively. Use that returned value to decide if the file exists: if(fp == NULL) { .....

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