473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to write a "long" value to a text file?

I want to write that "mjd1" value to a text file. I tried it using fprinf() function. but it dint work.
Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<dos.h>
  4. #include<stdio.h>
  5. void main()
  6. {
  7.    clrscr();
  8.    FILE *TempFile; 
  9.    int year,day,month,c=1,c1=0;
  10.    char *temp="buf.txt";
  11.    struct date d;
  12.    long double mjd=54832,mjd1,count=0;
  13.    cout<<"\nDay";
  14.    cin>>day;
  15.    cout<<"\nmonth";
  16.    cin>>month;
  17.    cout<<"\nyear";
  18.    cin>>year;
  19.    if(year!=2009)
  20.    {
  21.     for(int j=2009;j<year;j++)
  22.     {   count+=365;
  23.         if(j%4==0)
  24.         c1++;
  25.         cout<<"c1"<<c1;
  26.     }
  27.     }
  28.    if(year%4==0)
  29.    c+=2;
  30.    else c+=3;
  31.    cout<<"\nc2"<<c;
  32.    for(int i=1;i<month;i++)
  33.  
  34.        { if(i==11) c++;
  35.      if(i==4)  c++;
  36.      if(i==6)   c++;
  37.      if(i==9)   c++;
  38.  
  39.        count+=31;
  40.      }
  41.    cout<<"\n Count"<<count;
  42.    cout<<endl;
  43.    mjd1= count + day + mjd - c + c1;
  44.    cout<<"\nModified Julian Date:"<<mjd1;
  45.   TempFile=fopen(temp,"w+");
  46.   fprintf(TempFile,"Modified Julian date%s\t\n",mjd1);
  47.   fclose(TempFile);
  48.   getch();
  49.  
  50. }
  51.  
Oct 17 '09 #1
3 4273
donbock
2,426 Expert 2GB
mjd1 is declared as a long double. Are you sure you didn't want it to be a long int? Review the man page for fprintf. The %s conversion specifier is only for use with strings. You need something different for long doubles; and something else again for long ints.
Oct 17 '09 #2
Banfa
9,065 Expert Mod 8TB
Hi Don, IIRC there some weird and complex maths in calculation of julian dates that involves floating point operations. The output should be a long IIRC so mjd1 should cast to a unsigned(?) long for output.

However skorch1 you have used %s which indicates a pointer to a string, I wouldn't be surprised if this program caused a memory access violation. You need to cast mdj1 to unsiged long and use %lu in the fprintf format string and probably read up on format strings.
Oct 17 '09 #3
donbock
2,426 Expert 2GB
In my opinion, the definitive text for all date-related calculations is 'Calendrical Calculations' by Nachum Dershowitz and Edward Reingold. I have the first edition, copyrighted 1997. I see they are up to the 3rd edition now.
Oct 17 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Adnan Jamil | last post by:
Hi Guys, I have editing a SQL Server table field that have long text data. I am updating some text in this field. How can I update this field instead of re-write all text. With the Select...
1
by: Paul Thakur | last post by:
I am writing vbscript code in an .asp page. I need to display field values from a sql table consisting of several fields, one of them is of type "Long Text". This field contains XML data. I like to...
17
by: Adam Ierymenko | last post by:
I have a question that might have been asked before, but I have not been able to find anything via groups.google.com or any web search that is definative. I am writing an evolutionary AI...
6
by: Otto Wyss | last post by:
I've the following function declaration: wxTree GetLastChild (const wxTree& item, long& cookie) const; I'd like to make the cookie parameter optional, i.e. "long& cookie = ....", without...
7
by: bryan | last post by:
I think I'm missing something fundamental here. I'm trying to set an unsigned long value via a u_long pointer, however it coredumps everytime I get to that instruction. Here is a sample program...
65
by: kyle.tk | last post by:
I am trying to write a function to convert an ipv4 address that is held in the string char *ip to its long value equivalent. Here is what I have right now, but I can't seem to get it to work. ...
0
by: RON | last post by:
I have to read a long text field (it's a PDF) from SQL Server in a VB.NET (2003) app. Here's the code I have: Sub GetPDF(byval Path as string) 'objConnection created elsewhere; not the problem...
0
by: RON | last post by:
have to read a long text field (it's a PDF stored in a column) from SQL Server in a VB.NET (2003) app. Here's the code I have: Sub GetPDF(byval Path as string) 'objConnection created elsewhere;...
2
by: Pedrop | last post by:
I have to check if a long value is between two other long values (range check). Since all values are generated by shifting and because in java long is always signed the use of simple operators >= <=...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.