LinuxQuestions.org
Help answer threads with 0 replies.
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 07-27-2009, 09:01 AM   #1
StMatX
LQ Newbie
 
Registered: Jul 2009
Posts: 1

Rep: Reputation: 0
Gcc and working with device


Hi.

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)
{

FILE CDROM;
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)
{
perror(device_name);
}

if (CDROM==NULL)
{
printf("bad fopen\n");
exit(1);
}

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

Code:
if (CDROM==NULL)
{
printf("bad fopen\n");
exit(1);
}
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
bannock
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'.
 
  


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
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

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

All times are GMT -5. The time now is 02:47 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration