/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 as:parse error before '/' token... Can anyone please guide me how to direct my output to /dev/null.. Thanks, Divya |
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 |
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. |
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 |
This is one of the silliest things I have ever heard of; opening /dev/null in a program to write to it. :rolleyes:
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. |
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....:confused: Thanks,Divya |
man fopen()
Quote:
|
All times are GMT -5. The time now is 06:39 PM. |