473,836 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to use fopen()?

I wrote following program:

#include <stdio.h>

main()
{
FILE *file;

file=fopen(d:\r eadme.txt,"r");
if (file==NULL)
printf("fuck it's not working");
else
printf("finaly" );
}
My problem is that the only programs' result is : "fuck it's not working"
What do I wrong?
Nov 13 '05
19 31630
In article <bl**********@o ravannahka.hels inki.fi>, Joona I Palaste wrote:
Andreas Kahari <ak*******@free shell.org> scribbled the following:
In article <91************ **************@ posting.google. com>,
Taras wrote:
Andreas Kahari <ak*******@free shell.org> 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
Nov 13 '05 #11
Andreas Kahari <ak*******@free shell.org> writes:
In article <bl**********@o ravannahka.hels inki.fi>, Joona I Palaste wrote:
Andreas Kahari <ak*******@free shell.org> scribbled the following:
In article <91************ **************@ posting.google. com>,
Taras wrote:
Andreas Kahari <ak*******@free shell.org> 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
Nov 13 '05 #12

"Fao, Sean" <en**********@y ahoo.comI-WANT-NO-SPAM> wrote in message
news:rK******** ************@ne ws1.news.adelph ia.net...

"Taras" <te*****@o2.p l> wrote in message
news:91******** *************** ***@posting.goo gle.com...
I wrote following program:

#include <stdio.h>

main()
{
FILE *file;

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


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


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

:-)

Nov 13 '05 #13
"Micah Cowan" <mi***@cowan.na me> wrote in message
news:m3******** ****@localhost. localdomain...
....
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
Nov 13 '05 #14
August Derleth <li************ *****@onewest.n et> wrote in message news:<Xn******* *************** ************@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 ;-)
Nov 13 '05 #15
In <ff************ **************@ posting.google. com> ru**@webmail.co .za (goose) writes:
August Derleth <li************ *****@onewest.n et> wrote in message news:<Xn******* *************** ************@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: Da*****@ifh.de
Nov 13 '05 #16
Da*****@cern.ch (Dan Pop) wrote in message news:<bl******* ***@sunnews.cer n.ch>...
In <ff************ **************@ posting.google. com> ru**@webmail.co .za (goose) writes:
August Derleth <li************ *****@onewest.n et> wrote in message news:<Xn******* *************** ************@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)
Nov 13 '05 #17
On Sat, 04 Oct 2003 08:55:51 -0700, Taras wrote:
I wrote following program:

#include <stdio.h>

main()
{
FILE *file;

file=fopen(d:\r eadme.txt,"r");
if (file==NULL)
printf("fuck 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

Nov 13 '05 #18
In <ff************ **************@ posting.google. com> ru**@webmail.co .za (goose) writes:
Da*****@cern.c h (Dan Pop) wrote in message news:<bl******* ***@sunnews.cer n.ch>...
In <ff************ **************@ posting.google. com> ru**@webmail.co .za (goose) writes:
>August Derleth <li************ *****@onewest.n et> wrote in message news:<Xn******* *************** ************@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
implementati on-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: Da*****@ifh.de
Nov 13 '05 #19
"Zygmunt Krynicki" <zyga@_CUT_2zyg a.MEdyndns._OUT _org> wrote in message news:<pan.2003. 10.07.21.10.53. 948441@_CUT_2zy ga.MEdyndns._OU T_org>...
On Sat, 04 Oct 2003 08:55:51 -0700, Taras wrote:
I wrote following program:

#include <stdio.h>

main()
{
FILE *file;

file=fopen(d:\r eadme.txt,"r");
if (file==NULL)
printf("fuck it's not working");
else
printf("finaly" );
}
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
FILE *file;
file = fopen ("d:/reame.txt", "r");


file = fopen ("d:/readme.txt", "r"); /* :-) */
if (file == NULL) { printf ("f*** it's not working\n"); return EXIT_FAILURE;
} else { ^^^^^^ <--- no need for that
printf ("finally\n" );
fclose (f);
} ^ <--- or that
return EXIT_SUCCESS;
}

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


and returning a non-success value is better than
*always* returning EXIT_SUCCESS, even on failure.

goose,
Nov 13 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3695
by: Ming | last post by:
When I use fopen on the URL: fopen("http://home.pchome.com.tw/world/qoo4ko/110.jpg";, "r") I would get the following error message: -----------Error Message------------ Warning: fopen(): Circular redirect, aborting. Warning: fopen(http://home.pchome.com.tw/world/qoo4ko/110.jpg): failed to open stream: Permission denied ------------------------------------
11
5808
by: typingcat | last post by:
Is it possible to read another web page in PHP? If is ASP.NET, the code would be ------------ WebRequest req=WebRequest.Create("http://www.microsoft.com"); WebResponse res=req.GetResponse(); StreamReader sr = new StreamReader(res.GetResponseStream()); String Output=sr.ReadToEnd(); Response.Write("The content is : " + Output); --------
7
3039
by: git_cs | last post by:
Hey, guys and gals Somedays ago, I had asked for the DES algorithm in C language. Although I have written the algorthim in C myself, I am facing a peculiar problem, which I hope some of u guys and gals solve. I use Turbo C++ version 3.0 and WINXP as the operating system. Pls observe the following program. 1 #include<stdio.h> 2 #include<conio.h>
10
32434
by: Grocery Clerk | last post by:
I know open() returns a file descriptor and fopen() returns a pointer to FILE. The question is, when do I use fopen() and when do I use open()? Could someone give me an example when to use one over the other?
28
33204
by: Sathyaish | last post by:
If fopen fails, is there a way to know why?
13
22645
by: Blue | last post by:
Hi , Can any one please let me explain me the diffrences between "open"/ "fopen" or "read"/"fread" or "write/fwrite". I know that "open" /"read" / "write" are system calls and "fopen" /"fread" / "fwrite" are normal library functions. May be internally must be calling "fopen" /"fread" / "fwrite" functions.
10
4783
by: pjlsr | last post by:
It's close to twenty years since I used the C language and at that time I was doing only floating point computational work, nothing with strings or reading files. I tried to use fopen in the following manner. a file name is entered by keyboard , fgets is used to read the name. printf is used to confirm that the name was correctly read. Then infile=fopen("filename","r") is used to open the file which very definitly exists. It returns '0' as...
5
8846
by: Jae | last post by:
Real(const string &fileName) { FILE * myInputFile = fopen(fileName, "rt"); ..... fclose(myInputFile);
10
3967
by: Julia | last post by:
Hi, there, I am trying to append a binary file by using: FILE *strean; stream = fopen( "c:\temp.dat", "ba+" )); Is there a way that I can check if the file exists or not before fopen, because I will call different work flow by check the status of
25
3378
by: subramanian100in | last post by:
Consider the following program: #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv) { if (argc != 2) { printf("Usage: <program-name<text-file>\n");
0
10821
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10527
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9358
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7774
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6975
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5642
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5812
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4001
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3102
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.