473,786 Members | 2,571 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 #1
22 2292
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.
There's other problems too,
but let's see if we can get you compiling first.
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.


--
pete
May 16 '06 #2
On 16 May 2006 05:13:58 -0700, "no*********@gm ail.com"
<no*********@gm ail.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];

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


Most likely the errors are not "rediculus" (sic). A quick glance at
your code brings up the following:

(a) Wrong declaration for main().
(b) C89 does not allow mixing declarations with other statements.
(c) No check for fopen() return status.
(d) Use of "magic number" 100.
(e) Risk of buffer overflow in call to fscanf().
(f) Missing return statement.

May 16 '06 #3
"no*********@gm ail.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];

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.


Yes, there is something wrong with that. Reading the crimson
colored iculus error messages may give you a clue. I can see at
least three glaring errors, and at least two more tactical errors.

--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell. org/google/>
Also see <http://www.safalra.com/special/googlegroupsrep ly/>

May 16 '06 #4
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.
May 16 '06 #5
> wrong with this: (file related)

Oh come the off of it. I know what I am doing. 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.
NORI

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];

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 #6


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.

--
Er*********@sun .com

May 16 '06 #7

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];

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


Other than warnings, it compiles just fine for me. As pointed out
elsethread, it would be convenient if you list the errors you are
getting.

May 16 '06 #8

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];

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.


Well, as has already been pointed out, there's nothing (seriously)
wrong with your code, assuming C99, and that it's really your compiler
that gives out error messages. Rewritten thus:

#include <stdio.h>

int main(void) {
FILE *pfsin;
char mystr[100];

pfsin = fopen("msm.pfs" , "r");
fscanf(pfsin, "%s", mystr);
fclose(pfsin);

return 0;
}

it even compiles cleanly for "gcc -pedantic -W -Wall -Wextra -ansi".

So, unless you provide more specific information about the errors
you're seeing, I'm afraid nobody here can help. (Another look that
pesky line 42 sounds tempting, though.)

Alternatively, your compiler may be broken.

May 16 '06 #9
On 2006-05-16, no*********@gma il.com <no*********@gm ail.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];

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.


What are the errors?

I tried it on gcc and got a few warnings but it compiles OK.

The statement before a declaration is a parse error on some compilers,
so it seems most likely to be that. Try swapping the char mystr line
with the one above it.

Either that or you've got some dodgy macros somewhere (someone the other
day redefined FILE...)
May 16 '06 #10

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

Similar topics

125
14855
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
2838
by: titan0111 | last post by:
#include<iostream> #include<iomanip> #include<cstring> #include<fstream> using namespace std; class snowfall { private: int ft;
121
10180
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
3616
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
1745
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
1443
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
9650
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
9497
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
10363
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
10164
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
10110
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,...
1
7515
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
6748
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
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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.