Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > how to use fopen()?

Reply
Thread Tools

how to use fopen()?

 
 
Joona I Palaste
Guest
Posts: n/a
 
      10-05-2003
Andreas Kahari <(E-Mail Removed)> scribbled the following:
> In article <(E-Mail Removed) >,
> Taras wrote:
>> Andreas Kahari <(E-Mail Removed)> wrote in message
>> news:<(E-Mail Removed)>.. .

> [cut]
>>> Try writing it as
>>>
>>> file = fopen("d:/readme.txt", "r");

>>
>> Thank you , now it at last writes finally!


> Reads, I hope.


No, "writes" is correct. The OP's code:
---------------------------------------------------------------
#include <stdio.h>

main()
{
FILE *file;

file=fopen(d:\readme.txt,"r");
if (file==NULL)
printf("**** it's not working");
else
printf("finaly");
}
----------------------------------------------------------------
See the last printf() statement.

--
/-- Joona Palaste ((E-Mail Removed)) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
 
Reply With Quote
 
 
 
 
Andreas Kahari
Guest
Posts: n/a
 
      10-05-2003
In article <blp52m$cmm$(E-Mail Removed)>, Joona I Palaste wrote:
> Andreas Kahari <(E-Mail Removed)> scribbled the following:
>> In article <(E-Mail Removed) >,
>> Taras wrote:
>>> Andreas Kahari <(E-Mail Removed)> wrote in message

[cut]
>>>> file = fopen("d:/readme.txt", "r");
>>> Thank you , now it at last writes finally!

>> Reads, I hope.

> No, "writes" is correct. The OP's code:

[cut]
> See the last printf() statement.



No, that is possibly "displays", but I was concentrating more on
the fopen(), with the "r" mode.


--
Andreas Kähäri
 
Reply With Quote
 
 
 
 
Micah Cowan
Guest
Posts: n/a
 
      10-06-2003
Andreas Kahari <(E-Mail Removed)> writes:

> In article <blp52m$cmm$(E-Mail Removed)>, Joona I Palaste wrote:
> > Andreas Kahari <(E-Mail Removed)> scribbled the following:
> >> In article <(E-Mail Removed) >,
> >> Taras wrote:
> >>> Andreas Kahari <(E-Mail Removed)> wrote in message

> [cut]
> >>>> file = fopen("d:/readme.txt", "r");
> >>> Thank you , now it at last writes finally!
> >> Reads, I hope.

> > No, "writes" is correct. The OP's code:

> [cut]
> > See the last printf() statement.

>
>
> No, that is possibly "displays", but I was concentrating more on
> the fopen(), with the "r" mode.
>


You were concentrating wrong. And recall that the C standard has
no notion of "displays". He said what he meant, but he should
have used quotations, and the code's spelling should have been
fixed.

...now it at last writes, "finally"!

-Micah
 
Reply With Quote
 
Ashish
Guest
Posts: n/a
 
      10-06-2003

"Fao, Sean" <(E-Mail Removed)-WANT-NO-SPAM> wrote in message
news:rKEfb.3997$(E-Mail Removed) t...
>
> "Taras" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) om...
> > I wrote following program:
> >
> > #include <stdio.h>
> >
> > main()
> > {
> > FILE *file;
> >
> > file=fopen(d:\readme.txt,"r");

>
> file=fopen("d:\readme.txt", "r");


file = fopen("d:\\readme.txt", "r");





 
Reply With Quote
 
Peter Nilsson
Guest
Posts: n/a
 
      10-06-2003
"Micah Cowan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
....
> You were concentrating wrong. And recall that the C standard has
> no notion of "displays".


5.2.2 Character display semantics

It does have *some* notion.

--
Peter


 
Reply With Quote
 
goose
Guest
Posts: n/a
 
      10-07-2003
August Derleth <libertarian232003**@onewest.net> wrote in message news:<Xns940A9EF6CD3CFlibertarianonewestne@63.223. 6.93>...
>
> Yes. Any other declaration for main() is nonstandard and is erroneous.


unless, of course, its documented by the implementation.

> For
> example, void main() is incorrect despite its popularity among the less
> intelligent of the book and tutorial writers.



goose,
sometimes it is documented
 
Reply With Quote
 
Dan Pop
Guest
Posts: n/a
 
      10-07-2003
In <(E-Mail Removed) > http://www.velocityreviews.com/forums/(E-Mail Removed) (goose) writes:

>August Derleth <libertarian232003**@onewest.net> wrote in message news:<Xns940A9EF6CD3CFlibertarianonewestne@63.223. 6.93>...
>>
>> Yes. Any other declaration for main() is nonstandard and is erroneous.

>
>unless, of course, its documented by the implementation.


And if the implementation in question claims C99 conformance. In C89,
it doesn't make any difference whether the implementation documents other
main intefaces or not.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: (E-Mail Removed)
 
Reply With Quote
 
goose
Guest
Posts: n/a
 
      10-07-2003
(E-Mail Removed) (Dan Pop) wrote in message news:<blu57q$kr0$(E-Mail Removed)>...
> In <(E-Mail Removed) > (E-Mail Removed) (goose) writes:
>
> >August Derleth <libertarian232003**@onewest.net> wrote in message news:<Xns940A9EF6CD3CFlibertarianonewestne@63.223. 6.93>...
> >>
> >> Yes. Any other declaration for main() is nonstandard and is erroneous.

> >
> >unless, of course, its documented by the implementation.

>
> And if the implementation in question claims C99 conformance. In C89,
> it doesn't make any difference whether the implementation documents other
> main intefaces or not.
>


I'm not sure i follow. the c99 standard says "or some other
implementation-defined manner" after stating the legal return
values and arguments. does the c89 standard say differently with
regard to this ? I would like to see a quote (or perhaps a link).


tia
goose,
(I dont have the c89 standard, i *do* have c99 and the n869 file)
 
Reply With Quote
 
Zygmunt Krynicki
Guest
Posts: n/a
 
      10-07-2003
On Sat, 04 Oct 2003 08:55:51 -0700, Taras wrote:

> I wrote following program:
>
> #include <stdio.h>
>
> main()
> {
> FILE *file;
>
> file=fopen(d:\readme.txt,"r");
> if (file==NULL)
> printf("**** it's not working");
> else
> printf("finaly");
> }


#include <stdio.h>
#include <stdlib.h>

int main(void)
{
FILE *file;
file = fopen ("d:/reame.txt", "r");
if (file == NULL)
printf ("f*** it's not working\n");
else {
printf ("finally\n");
fclose (f);
}
return EXIT_SUCCESS;
}

I'd say \n is nice if you wish to have portable output, also EXIT_SUCCESS
is far better than guessing some popular value.

Regards

Zygmunt Krynicki

 
Reply With Quote
 
Dan Pop
Guest
Posts: n/a
 
      10-08-2003
In <(E-Mail Removed) > (E-Mail Removed) (goose) writes:

>(E-Mail Removed) (Dan Pop) wrote in message news:<blu57q$kr0$(E-Mail Removed)>...
>> In <(E-Mail Removed) > (E-Mail Removed) (goose) writes:
>>
>> >August Derleth <libertarian232003**@onewest.net> wrote in message news:<Xns940A9EF6CD3CFlibertarianonewestne@63.223. 6.93>...
>> >>
>> >> Yes. Any other declaration for main() is nonstandard and is erroneous.
>> >
>> >unless, of course, its documented by the implementation.

>>
>> And if the implementation in question claims C99 conformance. In C89,
>> it doesn't make any difference whether the implementation documents other
>> main intefaces or not.
>>

>
>I'm not sure i follow. the c99 standard says "or some other
>implementation-defined manner" after stating the legal return
>values and arguments. does the c89 standard say differently with
>regard to this ?


Yes. Otherwise, I wouldn't have mentioned C99 conformance.

>I would like to see a quote (or perhaps a link).


2.1.2.2 Hosted environment

A hosted environment need not be provided, but shall conform to the
following specifications if present.

"Program startup"

The function called at program startup is named main. The
implementation declares no prototype for this function. It can be
defined with no parameters:

int main(void) { /*...*/ }

or with two parameters (referred to here as argc and argv, though any
names may be used, as they are local to the function in which they are
declared):

int main(int argc, char *argv[]) { /*...*/ }

If they are defined, the parameters to the main function shall obey
the following constraints:

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: (E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Could not use ''; file already in use. M K ASP .Net 11 04-09-2008 11:35 AM
where to use CPLD & where to use FPGA? kulkarku@math.net VHDL 6 03-06-2006 07:27 AM
Can I use XPath or something to a remote Mac or Linux box and just query an xml file, not using web services and use encyrption? jake ASP .Net 0 07-06-2004 02:16 PM
Cannot use the profile "default" because it is in use, not. please.post@yur.re.ply Firefox 1 07-04-2004 03:41 AM



Advertisments