LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 09-15-2008, 11:02 PM   #1
divya_flora
LQ Newbie
 
Registered: Jul 2008
Posts: 15

Rep: Reputation: 0
/dev/null


hi all,
I am running a c++ program on linux...
I want to direct my output to /dev/null.
As,
printf("Could not open port \"%s\" at \"%d\" baud.\n"
,com_dev_ptr,DEFAULT_BAUDRATE) > /dev/null;

It gives an error asarse error before '/' token...
Can anyone please guide me how to direct my output to /dev/null..


Thanks,
Divya
 
Old 09-15-2008, 11:11 PM   #2
sameetLinux
LQ Newbie
 
Registered: Sep 2008
Posts: 7

Rep: Reputation: 0
Hi,
I am not an expert, but i believe you should be opening a file handle for /dev/null and write the string to the filehandle.

--sam
 
Old 09-15-2008, 11:16 PM   #3
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Wouldn't it be easier to just comment out the print statement? Why waste your resources writing to /dev/null when all you want is to not generate the output?

In any case, if you really want to write to /dev/null, you need to open /dev/null as an output stream, say _null, and then use fprintf(_null, . . .) to waste your cpu cycles.
 
Old 09-17-2008, 11:58 PM   #4
divya_flora
LQ Newbie
 
Registered: Jul 2008
Posts: 15

Original Poster
Rep: Reputation: 0
Hi,
Thanks a lot....I cannot actally avoid printf statements in my code..I tried but,it did'nt worked successfully..
So,i tried the other option..
I did :
FILE *_null;
_null= fopen ("/dev/null","w");
fprintf(_null,.................);
But,it is giving error as:
error: conflicting types for `_null'
error: previous declaration of `_null'
warning: data definition has no type or storage class
In function `probe_lcm':
warning: passing arg 1 of `fprintf' makes pointer from integer without a cast
In function `main':
warning: passing arg 1 of `fclose' makes pointer from integer without a cast

I am just new in using C++..can you please guide where i m wrong..
How can i sove this prob...

Thanks,Divya
 
Old 09-18-2008, 12:13 AM   #5
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
This is one of the silliest things I have ever heard of; opening /dev/null in a program to write to it.

But you should get away from _null as a file handle name. The message is telling you that you can't do that. Someplace buried in an include or something, _null is already defined. You should expect that because null has a specific meaning in C programs, and the underscore is very commonly used as a prefix in the include files. Change it to something unique, such as FILE *mycpucyclewastingnullfilepointer. That'll work.
 
Old 09-18-2008, 12:50 AM   #6
divya_flora
LQ Newbie
 
Registered: Jul 2008
Posts: 15

Original Poster
Rep: Reputation: 0
Wink

Hi,
Thanks for the reply......
Now,I have changed the code as:

FILE *mycpu1;
mycpu1= fopen("/DB/file1","w");
-----------------
fprintf(mycpu1,.................);
-----------------
fclose (mycpu1);

still getting these errors:
error: conflicting types for `mycpu1'
lcm-serial-test3.c:27: error: previous declaration of `mycpu1'
lcm-serial-test3.c:28: warning: data definition has no type or storage class
lcm-serial-test3.c: In function `probe_lcm':
lcm-serial-test3.c:121: warning: passing arg 1 of `fprintf' makes pointer from integer without a cast
lcm-serial-test3.c: In function `main':
lcm-serial-test3.c:279: warning: passing arg 1 of `fclose' makes pointer from integer without a cast

same errors again....



Thanks,Divya
 
Old 09-18-2008, 12:56 AM   #7
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
man fopen()


Quote:
fopen(3) - Linux man page
Name
fopen, fdopen, freopen - stream open functions
Synopsis
#include <stdio.h>
...
 
  


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
What would happen if I where to cat /dev/mem > /dev/null Joey.Dale Linux - General 11 07-26-2009 12:46 PM
Startx Permission problems on /dev/null and /dev/mem on freshly compiled 2.6.22.1 Eric_Cartman Linux - Kernel 2 09-09-2007 01:42 AM
Diff Between /dev/zero & /dev/null rajaniyer123 Solaris / OpenSolaris 4 07-02-2007 06:09 AM
What is meant by " file > /dev/null 2>&1 </dev/null " attockonian Linux - Newbie 5 06-30-2006 10:51 PM
mv c:\WINDOWS /dev/null; mount /dev/hda treehead LinuxQuestions.org Member Intro 5 10-19-2004 08:53 AM

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

All times are GMT -5. The time now is 07:36 PM.

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