473,803 Members | 4,157 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

fscanf

I'm doing something wrong and all I know to do is turn to clc. I have a
text file containing 2 doubles separated by a tab.

..26 0

Is the text. I want to read the two double and printf them out. Here's my
file.

#include <stdio.h>

int main() {
FILE *fp;
double x,y;
fp=fopen("zo"," r"); /*error checking out for brevity */
fscanf(fp,"%.2f \t%.2f",&string );
fclose(fp);
printf("%.2f%.2 f",x,y);
}

All I get is garbage that is contained in x and y. For whatever simple
reason that is beyond me evidently I can't read and printf out to stdin from
this text file. I don't think fread is really necessary.

Bill
Aug 17 '08
42 3821
On Aug 20, 2:01 am, Keith Thompson <ks...@mib.orgw rote:
vipps...@gmail. com writes:
On Aug 19, 4:06 am, "Bill Cunningham" <nos...@nspam.c omwrote:
"Keith Thompson" <ks...@mib.orgw rote in message
>news:ln******* *****@nuthaus.m ib.org...
vipps...@gmail. com writes:
On Aug 18, 5:23 am, Keith Thompson <ks...@mib.orgw rote:
correction (typo): cppreference.co m not cVppreference.c om.
Whoops, thanks for the correction.
Keith I hope this posts with no header problem above. I have k&r2. I use
thewww.cpprefer ence.comC section to look up return values mainly. I find
linux's man pages very vague IMO on my linux anyway, that is old.
I've never written that, stop lying, liar.

In message
<23ed5e23-0d31-4c1d-a28c-eacb1738f...@k1 3g2000hse.googl egroups.com>,
available at
<http://groups.google.c om/group/comp.lang.c/msg/0f9771c72501209 b>,
you, vippstar, did write:

correction (typo): cppreference.co m not cVppreference.c om.

In message <M0pqk.213$lf2. 146@trnddc07>, available at
<http://groups.google.c om/group/comp.lang.c/msg/a7ae6bac42f2ebf 4>,
Bill Cunningham correctly quoted what you wrote and correctly
attributed it to you; the number of prefixed ">" characters was even
correct. (He left in an extraneous attibution line with my name in
it, though he had snipped what I had written; I consider that a minor
error not worth complaining about, but I mention it here for
completeness.)

Before you call someone a liar, you need to be *very* sure that you're
right, that the other person's statement is false, and that the
falsehood was deliberate.

In my opinion, you owe Bill Cunningham an apology.
You're absolutely correct. The format of the message confused me. I
apologise to Bill Cunningham.
I got angry because IMHO Bill is a troll and I thought he reordered
the quotes (or something like that).

Aug 19 '08 #41
On Aug 20, 2:11 am, jameskuy...@ver izon.net wrote:
vipps...@gmail. com wrote:
<snip>
According to Google groups, those lines were indeed written by you, in
the following message: <http://groups.google.com/group/comp.lang.c/msg/
0f9771c72501209 b>
Has someone else been posting using your name?
I don't think so. That particular message was written and posted by
me.
Furthermore, I can't figure out why you'd object so strongly to having
those lines attributed to you. They show you finding a valid error,
which Keith acknowledged gratefully. It puts you in a pretty good
light, I would think. Therefore, even if they were actually written by
someone else, I would only expect you to be confused by the mis-
attribution, not angry about it. Am I missing something?
It was me who was missing something. Confusion lead to anger. See my
messsage to mr Thompson for complete explanation.
Aug 19 '08 #42
vi******@gmail. com said:
On Aug 20, 2:01 am, Keith Thompson <ks...@mib.orgw rote:
<snip>
>In my opinion, you owe Bill Cunningham an apology.

You're absolutely correct. The format of the message confused me. I
apologise to Bill Cunningham.
Handsomely done.
I got angry because IMHO Bill is a troll [...]
If you really think someone is a troll, the most important thing you can do
when reading their articles is *not get angry*.

That's (partly) what motivates trolls - they *want* to see you angry. If
Bill is a troll, perhaps he's the same, too.

If you can't deal calmly with the likes of Twink and Riley and McCormack
and (possibly) Cunningham - or if you simply think they're complete bozos
with the apparent mental capacity of a walnut and the reading
comprehension level of a two-year-old digestive biscuit - then I recommend
that you start using a killfile.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Aug 20 '08 #43

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

Similar topics

3
6736
by: Benedicte | last post by:
Hi, I'm getting some problems when using fscanf to read a file. This is a piece of the program code: main () { /*** Variable declaration ***/ FILE *vpfile; /*** Data file ***/
4
3062
by: Psibur | last post by:
Hello, trying to get back into c and was having issue with reading a simple text file with an aribtrary # of lines with 3 int's per line, with the eventual purpose of putting each int into an element of an array (eventually will be other things, but I'm sticking to int's for now). I.e.: 0 1 1 1 1 1 2 1 1 etc... The problem is it'll read and print all but the last line. Is there
7
5462
by: Thomas Sourmail | last post by:
Hi, I hope I am missing something simple, but.. here is my problem: I need my program to check the last column of a file, as in : a b c d target ref 0 0 0 0 1 a 1 0 0 0 1.5 b 2 0 0 0 2 c
1
2215
by: siliconwafer | last post by:
Hi All, here is one code: int main() { FILE*fp; unsigned long a; fp = fopen("my_file.txt","w+"); a = 24; fprintf(fp,"%ld",a); while(fscanf(fp,"%ld",&a) == 1) {
9
3231
by: quyvle | last post by:
I can't seem to get this function to work correctly. I'm wondering if anyone could help me out with this. So I'm using the fscanf function to read the input stream and store each string in the appropriate variables. Here's what I'm reading from another file: "# Number of power catergories: 9"
9
2372
by: kvnsmnsn | last post by:
Over the course of my career I've transitioned from an Ada programmer (am I dating myself?) to a C programmer to a Java programmer and now back to a C programmer with the job I've currently started. What I'd like to do is write a piece of C code that inputs to the pro- gram a line written to a file. The Java code written below does exactly what I want; it writes the <String"ab cd" to file "Java.Txt" and then reads it back in to variable...
37
4981
by: PeterOut | last post by:
I am using MS Visual C++ 6.0 on Windows XP 5.1 (SP2). I am not sure if this is a C, C++ or MS issue but fscanf has been randomly hanging on me. I make the call hundreds, if not thousands, of times but it hangs in different places with the same data. The offending code follows. ReadFile(char *csFileName) { float fFloat1, fFloat2;
59
5598
by: David Mathog | last post by:
Apologies if this is in the FAQ. I looked, but didn't find it. In a particular program the input read from a file is supposed to be: + 100 200 name1 - 101 201 name2 It is parsed by reading the + character, and then sending the remainder into fscanf() like
1
1276
momotaro
by: momotaro | last post by:
I have a small problem with the last fscanf in this function...every thing is logic in there but can't find the problem... plz help node *BuildGraph() { int range, vehicules, i, j, k;
0
9703
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
9564
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
10548
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
10316
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
10295
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
5500
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
5629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2970
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.