Open File Error
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the file open error in cobol company Business Learn more about hiring developers or posting ads with us Stack Overflow fopen Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 error code million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Error opening file (Resolved) up vote 3 down vote favorite RESOLVED. Problem - The lecturer uploaded a text file called file.txt and this resulted in a file "file.txt.txt"... I am feeling a mix of frustration and stupidity right now. Original problem------------------------------------------------------------------------- I'm having trouble with C using Visual Studio 2012 on Windows 7 trying to open a text file using fopen. I'm not too sure which directory this file.txt should be in so I tried placing it with the .vcxproj file AND the .exe file which is in the Debug directory created by VS. With no success, I tried including the full path to the file in the fopen function. This code compiles fine but when I run it, I get an error saying "No such file or directory" What am I doing wrong and how can I fix it? I'm really confused here and any help would be most welcome! Thanks in advance. Code below: int main(void) { FILE *fp; fp = fopen("C:\\Directory\\file.txt", "r"); if (fp == NULL) { perror("Error opening file\n"); } return 0; } c file directory fopen share|improve this question edited Oct 8 '12 at 4:34 asked Oct 7 '12 at 16:21 David Jiang 1613 Since your program doesn't produce the message 'No such file or directory', I believe that means your IDE is having problems finding the executable you've created, or you have not yet created the executable. Your code needs to include
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Error handling in file opening up vote 2 down vote favorite [Question 1] When I open a file http://stackoverflow.com/questions/12770578/error-opening-file-resolved into a function, generally I do something like this: int read_file (char *filename) { FILE *fin; if ( !(fin = fopen(filename, "r")) ) return 1; /* ... */ return fclose(fin); } int main () { char filename[100]; if ( read_file(filename) ) { perror(filename); exit(1); } return 0; } Generally 0 return value is for errors (right?) then I can change the previous code into: int read_file (char *filename) { FILE *fin; if ( http://stackoverflow.com/questions/21267716/error-handling-in-file-opening !(fin = fopen(filename, "r")) ) return 0; /* ... */ return !fclose(fin); } int main () { char filename[100]; if ( !read_file(filename) ) { perror(filename); exit(1); } return 0; } But I think that the first code is more clean. Another option is only change return 1; into return -1; (in the first code that I wrote). What's the best version? [Question 2] If I must handle more errors, is it correct a code like this? int read_file (char *filename, int **vet) { FILE *fin; if ( !(fin = fopen(filename, "r")) ) { perror(filename); return 1; } * vet = malloc (10 * sizeof(int)); if ( *vet == NULL ) { perror("Memory allocation error.\n"); return 1; } /* ... */ return fclose(fin); } int main () { char filename[100]; int *vet; if ( read_file(filename, &vet) ) exit(1); return 0; } c file error-handling fopen fclose share|improve this question asked Jan 21 '14 at 19:52 ᴜsᴇʀ 506314 will not (fin = fopen(filename, "r") be always true? –Dipto Jan 21 '14 at 19:59 2 In general we use 0 as the default error return as 0 refers to false and non null values refers to true. But when different errors needs to be handled we use negative values for errors. In your second question
copy or move. If this error http://www.ziprepair.com/cannot-open-file-valid-archive.php happens due to Internet connection problems (for example, noise on a phone line) then the problem can most easily be solved by discarding the damaged file and downloading a new copy. However, if you are not able to replace the corrupt Zip file, Zip Repair Pro should easily fix the problem. Download open file and try Zip Repair Pro using the download button below. Once repaired you will no longer get the error message "Cannot open file: it does not appear to be a valid archive": Current Version: 5.1.0.1431 Download Zip Repair Pro Click the "Download" button and download the file "ZipRepair-Setup.exe" to your computer. open file error Run ZipRepair-Setup.exe and follow the on-screen installation instructions. Ready to buy 100% secure ordering. Your privacy valued. Immediate product activation. Repair Tools Repair Excel Repair Word Repair Zip Repair BKF Repair X3F Repair CRW © GetData 2002-2016 All Rights Reserved. Zip Repair Home | Resellers | About Us | Sitemap | Privacy | User Agreement | Returns GetData products Data Recovery Software Data Recovery Software Photo Recovery Software iPod Recovery Software Email Message Recovery Email Recovery Software File Repair Repair My Backup - BKF Recovery Zip Repair Pro - Zip File Recovery X3F Repair Excel Repair Word Repair - FREE Document Repair CRW Repair - FREE Canon RAW Repair Windows Tools Explorer View for Windows Explorer Burn My Files - Burn CDs and DVDs Computer Forensic Software Mount Image Pro Virtual forensic computing Forensic Imager Phone Image Carver Forensic Explorer Contact support my cart » Account Zip Repair HomeScreenshotsCommon Zip ErrorsDownload EvaluationPurchase $29.95