C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 14th, 2012, 06:29 AM
hamed.samie hamed.samie is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 6 hamed.samie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 19 m 18 sec
Reputation Power: 0
Help plz - fopen()

Hello,

I have a problem here, I want to write a function called"myfopen()" instead of "fopen()"
for writing this function I must not use the <stdio.h> library,

Can you help me?

thanks a lot




I really needs your helps guys

Reply With Quote
  #2  
Old October 14th, 2012, 06:48 AM
bdb bdb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 156 bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 15 h 48 m 11 sec
Reputation Power: 32
No. fopen() returns a pointer to FILE. FILE is declared in <stdio.h>. You cannot return a pointer to FILE without using <stdio.h>.

What do you want the prototype for your myfopen() function to be?
Comments on this post
clifford agrees: ... unless you are too implementing your own FILE type - but that is less than clear here.

Reply With Quote
  #3  
Old October 14th, 2012, 06:52 AM
hamed.samie hamed.samie is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 6 hamed.samie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 19 m 18 sec
Reputation Power: 0
myfopen(const char*, const char*)

I know that i should start to do it with open() and write() or read() but i am not really good at this, and i dont know how to start.

Reply With Quote
  #4  
Old October 14th, 2012, 07:07 AM
clifford's Avatar
clifford clifford is offline
Contributing User
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Aug 2003
Location: UK
Posts: 4,808 clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Days 17 h 43 m 11 sec
Reputation Power: 1800
Compare the semantics and behaviour of fopen() with open() - your version will need to implement that missing functionality. You will need corresponding read, write and close operations as well - otherwise opening the file itself would be pointless. If you intend to use stdio fread/fwrite etc, then you will need implementation specific details of your particular libraries implementation.

It is not really reasonable to ask for help with so little initial effort. Since there are many design decisions that need to be made by you, and the scope of the task is significant. From the information you have provided, we would not really know where to start either.

There are a number of C libraries available as sourcecode that you might look at for inspiration. Here's one example I trust that on its own it will not help you too much (not least because it is written in K&R C rather than ISO/ANSI C, which is why I am happy to post the link as assistance rather than a solution. Your implementation will depend upon the scope and context of your particular assignment.

Last edited by clifford : October 14th, 2012 at 07:18 AM.

Reply With Quote
  #5  
Old October 14th, 2012, 07:08 AM
bdb bdb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 156 bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 15 h 48 m 11 sec
Reputation Power: 32
A prototype includes a return type

something like
Code:
FILE *fopen(const char *, const char *);

Reply With Quote
  #6  
Old October 14th, 2012, 07:33 AM
hamed.samie hamed.samie is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 6 hamed.samie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 19 m 18 sec
Reputation Power: 0
thanks man

Reply With Quote
  #7  
Old October 14th, 2012, 07:35 AM
hamed.samie hamed.samie is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 6 hamed.samie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 19 m 18 sec
Reputation Power: 0
Quote:
Originally Posted by bdb
A prototype includes a return type

something like
Code:
FILE *fopen(const char *, const char *);


yes exactly,

it is a little comlicated because we will have the error cases, but for me it is just the beginning the problem,

this function will return the address 0 in case of the error,

and his jub is to open a stream andinitialize it

Reply With Quote
  #8  
Old October 14th, 2012, 01:58 PM
clifford's Avatar
clifford clifford is offline
Contributing User
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Aug 2003
Location: UK
Posts: 4,808 clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Days 17 h 43 m 11 sec
Reputation Power: 1800
Quote:
Originally Posted by hamed.samie
yes exactly,
You have entirely missed bdb's point. FILE is a data structure defined by stdio.h. If it is your intent not to use stdio.h, you will have to define your own structure. Probably best in thsi case not to call it FILE but rather MYFILE perhaps.

The structure will contain anything your implementation needs to function in the manner you require, but I suggest that it will at least contain the file descriptor or handle returned by open().

Reply With Quote
  #9  
Old October 14th, 2012, 03:28 PM
hamed.samie hamed.samie is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 6 hamed.samie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 19 m 18 sec
Reputation Power: 0
No man i got it,
i already defined that :

typedef struct
{
int index;
int number_char_buff;
char buffer[BUFSIZE];


} myFILE;


an d i knew that i must use th e open() function instead of fopen()
but for the beginning i had problems i did sth but i am not sure that it is a good way or not, the problem is the time

this is it nt complete yet,

myFILE* myfopen(const char* name_file, const char* options)
{
char* adress_r=strchr(options,'r');
char* adress_w=strchr(options,'w');
char* adress_a=strchr(options,'a');
char* adress_t=strchr(options,'t');
myFILE *stream=NULL;
if ( adress_r== NULL && adress_w == NULL ) /* If r and w are not in options */
{
/*ERROOOOOOOOOOOOR !;*/

}
else if ( adress_r!= NULL && adress_w != NULL ) /* If r and w are in options*/
{} /*ERROOOOOOOOOOOOR !;*/
else if (adress_r != NULL) /* If just r is in options*/
{

stream=(myFILE*)malloc(sizeof(myFILE));
stream->index=open(name_file,O_RDONLY);


if (stream->index <0)
{
fatal(0,"This file do not exist \n \0", 5);
}
}
else if ( adress_a != NULL && adress_t != NULL ) /* If a and t are in otions*/
{} /*ERROOOOOOOOOOOOR !;*/
else if ( adress_a == NULL && adress_t == NULL ) /* If just w is in otions*/
{
stream=(myFILE*)malloc(sizeof(myFILE));
stream->index=open(name_file,O_CREAT|O_WRONLY,S_IRUSR|S_IWUSR|S_IROTH);
}
else if( adress_a != NULL) /* If just w and a are in otions*/
{
stream=(myFILE*)malloc(sizeof(myFILE));
stream->index=open(name_file,O_CREAT|O_WRONLY|O_APPEND,S_IRUSR|S_IWUSR|S_IROTH);
}
else /* If just w and t are in otions*/
{
stream=(myFILE*)malloc(sizeof(myFILE));
stream->index=open(name_file,O_CREAT|O_WRONLY|O_TRUNC,S_IRUSR|S_IWUSR|S_IROTH);
}

return stream;

}
Comments on this post
clifford disagrees: fail

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Help plz - fopen()

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap