LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 01-08-2004, 04:26 AM   #1
ratheesh
LQ Newbie
 
Registered: Nov 2003
Posts: 7

Rep: Reputation: 0
fprintf is not working in rpc server pgm


hi
for some program i want to print records to a file in a remote machine using rpc.when i tried to run this program ,the fprintf() statement failed. code is some thing like this,
......
fp = fopen("somefile","w");
fprintf(fp,"%s%s",str1,str2);
.....
why it is so?
 
Old 01-08-2004, 08:33 PM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
Use gdb on the core it dumps. My guess is that fopen is returning NULL for some reason (no write access to the file? Directory doesn't exist?)

Also, make sure that str1 and str2 are NULL-terminated.

I'd recommend changing your code to something like this:

-----
if((fp = fopen("somefile", "w")) == NULL)
{
fprintf(stderr, "Couldn't open file for writing: %s\n", strerror());
return;
}

fprintf(fp, "%s%s", str1, str2);
-----

You'll have to #include <errno.h> for strerror(). It would at least tell you the reason it can't open the file (if that really is the problem) then.

Last edited by itsme86; 01-08-2004 at 08:41 PM.
 
  


Reply



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
NFS server: RPC: Program not registered burbank Linux - Networking 11 09-15-2011 02:04 PM
NFS RPC: Port mapper failure - RPC: Unable to receive KEJP Linux - Networking 6 12-18-2006 02:14 AM
RPC not working berrance Linux - Software 7 10-10-2005 12:25 PM
rpc.lockd & rpc.statd twantrd Linux - General 1 05-21-2005 09:24 AM
Unmounting NFS filesystems: Cannot MOUNTPROG RPC: RPC ErnstVikenstein Linux - General 4 05-31-2003 12:10 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:44 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration