473,387 Members | 3,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

can't open file - says no file or directory

I have a weird issue. Can some one help.

When I hardcode abc.bin to inputFileName - I can open the file in cpp. But when I pass the same using an optional argument, it fails. Note that in both cases, fprintf, prints the inputFileName as abc.bin properly.

I get can't open - no file or directory.

Expand|Select|Wrap|Line Numbers
  1.    main()
  2.    {
  3.    char * inputFileName;
  4.    char * optarg;
  5.    inputFileName = optarg;  //doesn't work.
  6.    //inputFileName = "abc.bin"; //Works
  7.     fprintf(stderr, "inputFileName:%s \n",inputFileName);
  8.    }
  9.  
  10. Another function:
  11.     FILE *inFile;
  12.     if ( inFile != NULL )
  13.     {
  14.         inFile = fopen(inputFileName, "r+b");
  15.         if ( inFile == NULL )
  16.         {
  17.             fprintf(stderr, 
  18.                     "%s: can't open file %s: %s\n",
  19.                     ProgName, inputFileName, strerror(errno));
  20.             return NULL;
  21.         }
  22.     }
  23.  
Thank you
Jul 2 '10 #1
1 1933
weaknessforcats
9,208 Expert Mod 8TB
optarg is an uninitialized char*.

You need to get it pointed to a string containing the file name and path.
Jul 3 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Douglass Turner | last post by:
Hi, Please release me from my own private hell. Platform: SuSE 8.1 I'm installing python 2.3 tarball as follows: ../configure --enable-shared make
1
by: Brad Jones | last post by:
I am having problems opening a .aspx file. I have installed the .NET 1.1 Framework. When I go into IIS, Websites, Default Website, then look at the properties under documents, default.aspx is...
4
by: Menü Sargut | last post by:
Hello All How can I open a PDF file. (shellexecute?) Thanks Mengü
0
by: Arthur Naoumidis | last post by:
I have an AS.net web app that I am using to upoload data files into my application. I am trying to upload a DBF file and I don't have access to the associated CDX file - is there some option in the...
1
by: Luis Ramos | last post by:
Happy new year for everybody... My problem is this: I can open a random file with vs2005 this way(normal project), but not in a smart device project. example: Structure Record public ID As...
3
by: MSDN | last post by:
hello, Need to be able to open .msg ( Outlook email file ) in IE or allow IE to launch Outlook just like opening PDF links Thank you, SA
22
by: fniles | last post by:
I have a .CSV file (comma delimited) that I want to open using OLEDB, but I get the error "External table is not in the expected format." If I save the .CSV file to an .XLS file, I can open the...
1
by: javarules222000 | last post by:
Here's what I have so far. I just cant figure out how to read my file into an array. If you have any idea how to do this PLEASE help me!!! import java.io.*; import java.util.*; class bored{ ...
0
by: Coaster | last post by:
I think I can but haven't seen an example. An app I inherited uses schema.ini and it forces all the files to have the same name because of the current format Format=Delimited(|) .... I'd...
5
by: Aussie Rules | last post by:
Hi, I have a database that contains the name of PDF file and page numbers for articles. Is it possible using my vb.net winform application, open up the pdf and then move to the relevant page...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.