473,799 Members | 3,329 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is wrong with this. (files)

Okay. I'm quite embarased to be asking this but I cannot seem to get
files to work. I don't know what the problem is. Is there something
wrong with this: (file related)

#include <stdio.h>
main() {
FILE *pfsin;
pfsin = fopen("msm.pfs" , "r");
char mystr[100];

fscanf(pfsin, "%s", mystr);
fclose(pfsin);
}

Thanks in advanced, but I have seen several examples of code that looks
EXACLTY like this, and for some reason my compiler is giving me
rediculus errors.
Nori

May 16 '06
22 2296
jacob navia said:
pete a écrit :
no*********@gma il.com wrote:
Okay. I'm quite embarased to be asking this but I cannot seem to get
files to work. I don't know what the problem is. Is there something
wrong with this: (file related)

#include <stdio.h>
main() {
FILE *pfsin;

pfsin = fopen("msm.pfs" , "r");
char mystr[100];

The above two lines of code are out of order for C89.


You are living in the past Pete.


No, he's living in the present reality where almost nobody has a conforming
C99 compiler.
We are 2006 and the C standard is 7 years old. The above likes are
standard C.


Standard, yes. Portable, no. The explanation pete gave of the OP's problem
is entirely plausible.

Just because a few guys on a committee somewhere say "hey, let's change the
language definition", that does not automatically upgrade every compiler
installation in the world to meet the new definition.

Based on your past performance, I do not expect you to understand this.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
May 16 '06 #11
jacob navia wrote:
pete a écrit :
no*********@gma il.com wrote:
Okay. I'm quite embarased to be asking this but I cannot seem to get
files to work. I don't know what the problem is. Is there something
wrong with this: (file related)

#include <stdio.h>
main() {
FILE *pfsin;

pfsin = fopen("msm.pfs" , "r");
char mystr[100];

The above two lines of code are out of order for C89.


You are living in the past Pete. We are 2006 and the C standard is 7
years old. The above likes are standard C.


Well, the program can't have been C99 since it used implicit int for
main. Also, seeing as very few compilers are C99 compliant (something
you are well aware of) it is reasonable to guess that the OPs compiler
is not C99 compliant and therefore point this out as a possible error.

Once MS VC++ and gcc are both C99 compliant (neither is currently and MS
has made no attempt at it) you might have a little (but not much since
there are lots of compilers for embedded systems as well) cause for
complaint when people point out that things are not valid C89.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
May 16 '06 #12
Flash Gordon wrote:

jacob navia wrote:
pete a écrit :
no*********@gma il.com wrote:

Okay.
I'm quite embarased to be asking this but I cannot seem to get
files to work. I don't know what the problem is.
Is there something
wrong with this: (file related)

#include <stdio.h>
main() {
FILE *pfsin;

pfsin = fopen("msm.pfs" , "r");
char mystr[100];
The above two lines of code are out of order for C89.


You are living in the past Pete. We are 2006 and the C standard is 7
years old. The above likes are standard C.


Well, the program can't have been C99 since it used implicit int for
main.


So, there! Ha!

OP just gave a response as stupid as jacob navia's,
elsewhere on this thread, to which Eric Sosman replied.

--
pete
May 16 '06 #13
on cl version 14.00.50727.42
i've:

test.c(4) : warning C4996: 'fopen' was declared deprecated
C:\Programmi\Mi crosoft Visual Studio 8\VC\INCLUDE\st dio.h(234)
: see dec
laration of 'fopen'
Message: 'This function or variable may be unsafe. Consider
using fopen_
s instead. To disable deprecation, use _CRT_SECURE_NO_ DEPRECATE. See
online help
for details.'
test.c(5) : error C2143: syntax error : missing ';' before 'type'
test.c(9) : error C2065: 'mystr' : undeclared identifier
the problem is related to mixing declaration with expression.
switching
pfsin = fopen("msm.pfs" , "r");
char mystr[100];
it's compile.

May 17 '06 #14
Luca Benini said:
on cl version 14.00.50727.42
i've:

test.c(4) : warning C4996: 'fopen' was declared deprecated
Never heard such nonsense.
C:\Programmi\Mi crosoft Visual Studio 8\VC\INCLUDE\st dio.h(234)
: see dec
laration of 'fopen'
Message: 'This function or variable may be unsafe. Consider
using fopen_
s instead.
Ridiculous. If their fopen is unsafe, they should fix it.
test.c(5) : error C2143: syntax error : missing ';' before 'type'
test.c(9) : error C2065: 'mystr' : undeclared identifier
the problem is related to mixing declaration with expression.
switching
pfsin = fopen("msm.pfs" , "r");
char mystr[100];
it's compile.


Declarations first, code afterwards. That's how C does it.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
May 17 '06 #15
Richard Heathfield wrote:
Declarations first, code afterwards. That's how C does it.


I think you mean "statements " instead of "code".
That's how C89 does it in a block, but it's not required by C99.
Declarations are code, sometimes with side effects.

FILE *pfsin;
pfsin = fopen("msm.pfs" , "r");
char mystr[100];

could also have been fixed for C89 as

FILE *pfsin = fopen("msm.pfs" , "r");
char mystr[100];

--
pete
May 17 '06 #16
Eric Sosman wrote:

no*********@gma il.com wrote On 05/16/06 10:36,:
wrong with this: (file related)

Oh come the off of it. I know what I am doing.


Then why are you asking for help?
This was simply and
example. Frankly I do not care about C89. I spacificly said FILE
REALTED.
I know that I'm risking this that and the next thing, okay.
I don't care about tactical errors. Its an example not killer-app
source code. Why don't keep your comments about C89 and risks and
tactical errors to your self,
that has nothing to do with my question,
and actually try to help instead of trying to make yourselfs feel
superior.


Your question was about the "rediculous errors" your
compiler generates for your code. Of course, you lacked
the wit to transcribe any of those "rediculous errors" so
someone could actually look at them ...

"Doctor, it hurts!"

"Where does it hurt?"

"Never mind, just hurry up and heal me!"

My diagnosis: You have an error on line 42. True,
there were only nine lines (one of them blank) in the code
you showed, but you've admitted ("This was simply and [sic]
example") that you haven't shown your actual code. Go fix
line 42, and all will be well.


With trouble shooting in general,
be it either automotive or programming,
when somebody tells you that they've got a problem
and that they know what the problem definitely isn't,
then that's the first place I want to start looking.
My experience is that there is about 50% chance
that that's the problem.

--
pete
May 17 '06 #17
pete said:
Richard Heathfield wrote:
Declarations first, code afterwards. That's how C does it.
I think you mean "statements " instead of "code".


<shrug>
That's how C89 does it in a block, but it's not required by C99.


If the OP had C99, he wouldn't have had the problem. Or if the OP had put
his declarations above his statements, he wouldn't have had the problem.

The first "if" is rather tricky to fix, but the second is trivial.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
May 17 '06 #18
pete wrote:
Eric Sosman wrote:

no*********@gma il.com wrote On 05/16/06 10:36,:
>>wrong with this: (file related)
>
>
> Oh come the off of it. I know what I am doing.


Then why are you asking for help?
> This was simply and
> example. Frankly I do not care about C89. I spacificly said FILE
> REALTED.
> I know that I'm risking this that and the next thing, okay.
> I don't care about tactical errors. Its an example not killer-app
> source code. Why don't keep your comments about C89 and risks and
> tactical errors to your self,
> that has nothing to do with my question,
> and actually try to help instead of trying to make yourselfs feel
> superior.


Your question was about the "rediculous errors" your
compiler generates for your code. Of course, you lacked
the wit to transcribe any of those "rediculous errors" so
someone could actually look at them ...

"Doctor, it hurts!"

"Where does it hurt?"

"Never mind, just hurry up and heal me!"

My diagnosis: You have an error on line 42. True,
there were only nine lines (one of them blank) in the code
you showed, but you've admitted ("This was simply and [sic]
example") that you haven't shown your actual code. Go fix
line 42, and all will be well.


With trouble shooting in general,
be it either automotive or programming,
when somebody tells you that they've got a problem
and that they know what the problem definitely isn't,
then that's the first place I want to start looking.
My experience is that there is about 50% chance
that that's the problem.


Since any given statement either is or is not a problem, any given statement
has a 50% chance of being the problem.

May 18 '06 #19
jab3 said:
pete wrote:
With trouble shooting in general,
be it either automotive or programming,
when somebody tells you that they've got a problem
and that they know what the problem definitely isn't,
then that's the first place I want to start looking.
My experience is that there is about 50% chance
that that's the problem.

pete - that jibes pretty well with my experience, too, although I'd have put
the probability somewhat higher.
Since any given statement either is or is not a problem, any given
statement has a 50% chance of being the problem.


If you truly believe that two mutually exclusive possibilities are
necessarily of equal probability, I offer you the following bet:

Given suitable precautions to prevent cheating, you will put down $5000 and
I will put down $10000 - so there's $15000 on the table - and then a
trusted third party will put a hundred fair coins (one side heads, the
other side tails) into a sack, shake 'em around a bit, and then spill them
onto a tabletop. Either they will all come out heads, or they won't, so
that's 50-50, right? So - if they all come down heads, you get to keep the
$15000, despite only a $5000 stake. That's good odds for you. If the other
50% chance happens, though, I get the $15000 instead.

Deal?

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
May 18 '06 #20

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

Similar topics

125
14863
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from software giant such as Microsoft SQL Server, Oracle, and Sybase? Is PostgreSQL reliable enough to be used for high-end commercial application? Thanks
30
9601
by: RC | last post by:
I want to do <hr noshade size="5" width="80%"> by use CSS instead HTML. I try <style type="text/css"> HR { size: 5px; width: 80%; length: 5px; height: 5px; border-style:padding: 0}
5
2839
by: titan0111 | last post by:
#include<iostream> #include<iomanip> #include<cstring> #include<fstream> using namespace std; class snowfall { private: int ft;
121
10188
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode support IDEs are DreamWeaver 8 and Zend PHP Studio. DreamWeaver provides full support for Unicode. However, DreamWeaver is a web editor rather than a PHP IDE. It only supports basic IntelliSense (or code completion) and doesn't have anything...
2
5745
by: Qiao Yun | last post by:
I used vc++.net (visual studio .net ) to open a project which can work well in vc++6.0. I succeeded in compiling the project in vc++.net in release mode . But when I tried to compile the project in debug mode, the following errors happened: d:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xdebug(29): error C2365: 'new' : redefinition; previous definition was a 'member function' d:\Program Files\Microsoft Visual Studio...
2
3618
by: Rod | last post by:
I've been struggling with this thing for 2 days, and after searching the 'net for help, I cannot find what is wrong. We're using Crystal Reports XI Release 2, with Visual Studio .NET 2003 in an ASP.NET 1.1 application. I've got a CrystralReportsViewer control on an ASP.NET page. Once the page gets hit I get the following error message (this is running on my development machine):
7
1748
by: Altemir | last post by:
SOME BACKGROUND: I am new to ASP.NET, but somehow managed to install a perfectly working ..aspx page on our production server that I compiled in Visual Studio. However, I recently needed to update it, so I first added a ".old" suffix to the MyPage.aspx, MyProject.dll, and global.asax files on the production server so I had a backup copy of the original files in case something went wrong. Indeed, something did go wrong when I installed...
1
1446
by: x40 | last post by:
I try to learn python thru solving some interisting problem, found google trasure hunt, write first program ( but cant find whats wrong). # Unzip the archive, then process the resulting files to obtain a numeric result. You'll be taking the sum of lines from files matching a certain description, and multiplying those sums together to obtain a final result. Note that files have many different extensions, like '.pdf' and '.js', but all...
12
1856
by: vijayarl | last post by:
Hi All, Thanks in Advance !!!! I have one config file & am reading that file.later i am using one of the value specified in the config file & trying to get the files placed in the directory into the array. problem is when i try to print the array varaible it doesn't hold any value even though i have placed some files under searching directory... don't know where it's going wrong ??? can any one help me on this ???
5
1091
by: Timothy Madden | last post by:
Hello I see there is now why to truncate a file (in C or C++) and that I have to use platform-specific functions for truncating files. Anyone knows why ? I mean C/C++ evolved over many years now, and still, people making _the_ standards never decided to include such a function. Even in POSIX it was included only in recent versions, mostly not fully supported yet.
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9541
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10485
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
10252
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...
1
10231
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9073
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...
0
6805
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();...
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
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.