Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

how to use fopen()?

 
 
Taras
Guest
Posts: n/a
 
      10-04-2003
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");
}


My problem is that the only programs' result is : "**** it's not working"
What do I wrong?
 
Reply With Quote
 
 
 
 
Andreas Kahari
Guest
Posts: n/a
 
      10-04-2003
In article <(E-Mail Removed) >, Taras wrote:
> I wrote following program:
>
> #include <stdio.h>
>
> main()


int main(void)

> {
> FILE *file;
>
> file=fopen(d:\readme.txt,"r");
> if (file==NULL)
> printf("**** it's not working");
> else
> printf("finaly");


fclose(file);
return 0;

> }
>
>
> My problem is that the only programs' result is : "**** it's not working"


I doubt it's even that, you have a syntax error on the line

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

Try writing it as

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

instead, or escape the backslash:

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


--
Andreas Kähäri
 
Reply With Quote
 
 
 
 
Fao, Sean
Guest
Posts: n/a
 
      10-04-2003

"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");

> if (file==NULL)
> printf("**** it's not working");
> else
> printf("finaly");
> }
>
>
> My problem is that the only programs' result is : "**** it's not working"
> What do I wrong?


 
Reply With Quote
 
Fao, Sean
Guest
Posts: n/a
 
      10-04-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");
>
> > if (file==NULL)
> > printf("**** it's not working");
> > else
> > printf("finaly");


/* Oops, I missed this */
fclose(file);
return 0;

> > }


 
Reply With Quote
 
Fao, Sean
Guest
Posts: n/a
 
      10-04-2003
"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");
> if (file==NULL)
> printf("**** it's not working");
> else
> printf("finaly");
> }


Ok, this is the last time that I fix code when I've only had 2 hours of
sleep. Ignore everything I've written up to this point and read what the
other poster wrote.

 
Reply With Quote
 
no@no.invalid
Guest
Posts: n/a
 
      10-04-2003

On 4-Oct-2003, Andreas Kahari <(E-Mail Removed)> wrote:

> In article <(E-Mail Removed) >, Taras wrote:
> > I wrote following program:
> >
> > #include <stdio.h>
> >
> > main()

>
> int main(void)
>
> > {
> > FILE *file;
> >
> > file=fopen(d:\readme.txt,"r");
> > if (file==NULL)
> > printf("**** it's not working");
> > else
> > printf("finaly");

>
> fclose(file);
> return 0;
>
> > }



Do we *have* to point out the int main(void) return 0 etc things ?
















 
Reply With Quote
 
August Derleth
Guest
Posts: n/a
 
      10-04-2003
"(E-Mail Removed)" <(E-Mail Removed)> wrote in
news:(E-Mail Removed) on Sat 04 Oct 2003
01:11:21p:

>
> Do we *have* to point out the int main(void) return 0 etc things ?


Yes. Any other declaration for main() is nonstandard and is erroneous. For
example, void main() is incorrect despite its popularity among the less
intelligent of the book and tutorial writers.

 
Reply With Quote
 
Mike Wahler
Guest
Posts: n/a
 
      10-04-2003
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

>
> Do we *have* to point out the int main(void) return 0 etc things ?


No, of course you don't have to.
But those who want to convey correctness will.
I seems that many instructors don't, through
ignorance, apathy, or whatever.


-Mike


 
Reply With Quote
 
Taras
Guest
Posts: n/a
 
      10-05-2003
Andreas Kahari <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>.. .
> In article <(E-Mail Removed) >, Taras wrote:
> > I wrote following program:
> >
> > #include <stdio.h>
> >
> > main()

>
> int main(void)
>
> > {
> > FILE *file;
> >
> > file=fopen(d:\readme.txt,"r");
> > if (file==NULL)
> > printf("**** it's not working");
> > else
> > printf("finaly");

>
> fclose(file);
> return 0;
>
> > }
> >
> >
> > My problem is that the only programs' result is : "**** it's not working"

>
> I doubt it's even that, you have a syntax error on the line
>
> file=fopen(d:\readme.txt,"r");
>
> Try writing it as
>
> file = fopen("d:/readme.txt", "r");
>
> instead, or escape the backslash:
>
> file = fopen("d:\\readme.txt", "r");



Thank you , now it at last writes finally!
 
Reply With Quote
 
Andreas Kahari
Guest
Posts: n/a
 
      10-05-2003
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.


--
Andreas Kähäri
 
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