Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 07-27-2009, 09:01 AM   #1
LQ Newbie
Registered: Jul 2009
Posts: 1

Rep: Reputation: 0
Gcc and working with device


I wish to open device like cdrom in my gcc application, for the start, but i dont have any success.

So, can anyone do some guidness to me, how to open device.

I'm trying with ...

int main(int argc, char** argv)

int sockfd;
int cdrom_fd;
char* device_name = argv[1];

// CDROM=open("/mnt/cdrom/file1","rb");

if ((cdrom_fd = open(device_name,O_RDONLY))==-1)

printf("bad fopen\n");

return 0;

I guess i missing the point somewhere.

Sorry, i'm a beginner.

Tnx for help.
Old 07-27-2009, 12:48 PM   #2
Sergei Steshenko
Senior Member
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
You code doesn't make sense, for example

printf("bad fopen\n");
checks value of undefined variable.

When you compile, use '-Wall -Wextra' on command line and first make sure you have zero warnings.

Use CODE /CODE tags around your code - the easiest way is to use advanced editing mode in this forum and its '#' button.
Old 07-27-2009, 10:23 PM   #3
LQ Newbie
Registered: Jun 2009
Location: Toronto
Distribution: Ubuntu, Fedora
Posts: 24

Rep: Reputation: 18
You are also missing some headers, you probably want to include stdio.h, and the function to open a file is 'fopen' not 'open'.


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
USB drive not working properly, read only device? (USB key storage device) Arodef Linux - Hardware 14 01-01-2010 08:32 AM
gcc -ly not working.. sagar_parmar Fedora 5 10-18-2008 12:13 AM
"USB device stops working after a time" 'fix' stops cdrom device mount/readability adamben Slackware 6 04-18-2007 02:18 PM
upgrade opnessh on a device which does not have gcc,rpm ldilse Linux - Software 1 09-06-2005 11:29 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:33 PM.

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