LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-03-2011, 01:14 AM   #1
shamjs
Member
 
Registered: Sep 2011
Posts: 80

Rep: Reputation: Disabled
problem in opening .csv file


Hi all,
i need to read a Tutorb.csv file but im having some problem to open it.
this is my sample code
Code:
/*********test.h**********/
.
.
A=Utils::GetMatrix("Tutorb.csv");/*i have placed Tutorb.csv in same directory of test.h(i.e Tutorb.csv is placed in same path of test.h),so there is no misplacing of Tutorb.csv file*/
cout<<A;
cout.flush();
.
.
Code:
/******utils.h*******/
.
.
static Array2D<REAL> GetMatrix(const char* filename)
		{     
			char szLine[MAXLINE];
			char seps[]=",";


			FILE* fp=fopen(filename,"r");
			if (fp==NULL)
			{
				printf("Failed to open data file");
				return Array2D<REAL>(0,0);
			}
//here are some code that reads the file
}
.
.
please guide me where i have went wrong.
waiting for your reply.

Last edited by shamjs; 11-03-2011 at 01:17 AM.
 
Old 11-03-2011, 01:21 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,715

Rep: Reputation: 488Reputation: 488Reputation: 488Reputation: 488Reputation: 488
Try this:
Code:
if (fp==NULL) {
    fprintf (stderr, "*** Failed to open data file '%s': errno=%d %s\n",
             filename, errno, strerror (errno));
}
Don't forget to include errno.h
 
Old 11-03-2011, 01:38 AM   #3
shamjs
Member
 
Registered: Sep 2011
Posts: 80

Original Poster
Rep: Reputation: Disabled
i have included those lines
i got the error saying

*******failed to open data file 'Tutorb.csv':errno=2 no such file or directory

but i have placed that file in proper path
 
Old 11-03-2011, 02:54 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,715

Rep: Reputation: 488Reputation: 488Reputation: 488Reputation: 488Reputation: 488
> but i have placed that file in proper path

Then your program runs somewhere else... try this: system ("pwd");

PS: I hope by 'path' you meant 'directory'; fopen/open doesn't search PATH

Last edited by NevemTeve; 11-03-2011 at 02:58 AM. Reason: A note on 'path'
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Problem With Opening WMV File hitmen Linux - Newbie 14 10-10-2012 12:59 PM
Problem for Opening any file with VIM ? raviteja_s Linux - Newbie 1 10-02-2010 03:35 AM
Comparing two csv files and write different record in third CSV file irfanb146 Linux - Newbie 3 06-30-2008 09:15 PM
problem with opening file function in c++ tinieprotonjam Programming 2 02-14-2007 09:48 PM
bad problem opening a bin file. dirky Linux - Newbie 1 09-25-2004 10:13 PM


All times are GMT -5. The time now is 04:27 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration