linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* RE: problem in open sys call
@ 2004-04-20 19:22 Huber, George K RDECOM CERDEC STCD SRI
  2004-04-21  9:10 ` joy
  0 siblings, 1 reply; 8+ messages in thread
From: Huber, George K RDECOM CERDEC STCD SRI @ 2004-04-20 19:22 UTC (permalink / raw)
  To: 'gracecott@sancharnet.in', linux-c-programming

Hi,

Try this:

	if((fd=open(opcode, O_RDONLY))==-1)
      {
	  printf("Open failed, error code: %d\n%s\n", errno, strerror(errno)
      }
		
you may need to add errno.h and string.h to the list of includes.  This will
give you the error code and desctiption of why open is failing.

George Huber
SRI, International

-----Original Message-----
From: linux-c-programming-owner@vger.kernel.org
[mailto:linux-c-programming-owner@vger.kernel.org]On Behalf Of joy
Sent: Tuesday, April 20, 2004 2:32 PM
To: linux-c-programming@vger.kernel.org
Subject: problem in open sys call


Hi,
I have a small prblem i the open call. it fails every time and I dont 
know why.

thanx in advance,
Joy.M.M

^ permalink raw reply	[flat|nested] 8+ messages in thread
* problem in open sys call
@ 2004-04-20 18:31 joy
  2004-04-20 20:06 ` Glynn Clements
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: joy @ 2004-04-20 18:31 UTC (permalink / raw)
  To: linux-c-programming

[-- Attachment #1: Type: text/plain, Size: 112 bytes --]

Hi,
I have a small prblem i the open call. it fails every time and I dont 
know why.

thanx in advance,
Joy.M.M

[-- Attachment #2: opgen.c --]
[-- Type: text/plain, Size: 1021 bytes --]


#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<string.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>

const char opcode[]="opcode.sheet";
const char target[]="opcode.sheet";

main()
{
	char buff[8192],temp[10],bin=0,opcode[3];
	int fd,fd1,bytes_read=8192,count,i=0,inter_count=0;
	int offset=0,j=0,tempy;
	char head[]="OPCODE SHEET";
	
	if((fd=open(opcode, O_RDONLY))==-1)
		printf("oops");
	if((fd1=open(target, O_RDWR|O_CREAT))==-1)
		printf("O");
	while(bytes_read==8192)
	{
	bytes_read=read(fd,buff,8192);
	while(inter_count<bytes_read)
	{
		i=0;
		do
		{
			bin=buff[inter_count];
			temp[i]=buff[inter_count];
			inter_count++;
			i++;
		}while(bin!=10);
		temp[i++]=0;
		j=0;
	write(fd1,head,sizeof(head));
		for(j=0;j<i;j++)
		{
			tempy=(int)(temp[j]-0);
			offset+=tempy;
		}
		if(lseek(fd1,offset,SEEK_SET)==-1)
			printf("HI");
		
		printf("%s : ",temp);
		scanf("%s",opcode);
	      write(fd1,opcode,sizeof(opcode));
		printf("%s %d \n",temp ,offset);
	}
	}
	return(0);
}

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-04-21 10:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-04-20 19:22 problem in open sys call Huber, George K RDECOM CERDEC STCD SRI
2004-04-21  9:10 ` joy
2004-04-21 10:08   ` Holger Kiehl
  -- strict thread matches above, loose matches on Subject: below --
2004-04-20 18:31 joy
2004-04-20 20:06 ` Glynn Clements
2004-04-21  9:00   ` joy
2004-04-20 21:35 ` Steven Smith
2004-04-21  6:14 ` Vadiraj C S

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).