473,591 Members | 2,810 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

why does my code stop responding...?

SS
It seems that my code locks my machine up after the " fclose(datafile );"
command
I guess I'm not following the next bit of code on properly.
Can someone help me out??

SS
=============== =============== =============== =============== =============== =
==========
# include <stdio.h>
main ()
{
FILE *datafile;
datafile = fopen ("a:\\lab1-1-1.csv","w");
float Dt = 0.01;
float u = 1;
float Tmax = 2;
float t = 0 , e = 0, y1 = 0, y = 0;
float J = 0.02;
float k = 10;
float B = 0.5;
while (t<=Tmax)
{
e = u - y ;
y1 = y1 +(k* Dt*e);
y = y+Dt/J*(k*y1-B*y);
printf("%7.3f %7.3f \n",t,y);
fprintf(datafil e,"%7.3f, %7.3f \n ", t,y);
t = t+Dt;
}
fclose (datafile);
//ok to here?

FILE *datafileb;
datafileb = fopen ("a:\\lab1-12.csv","w");
float Dt2 = 0.01;
float u2 = 1;
float Tmax2 = 2;
float t2 = 0 , e2 = 0, y12 = 0, y2 = 0;
float J2 = 0.02;
float k2 = 1;
float B2 = 0.5;
while (t2<=Tmax2);
{
e2 = u2 - y2 ;
y12 = y12 +(k2* Dt2*e2);
y2 = y2+Dt2/J2*(k2*y12-B2*y2);
printf("%7.3f %7.3f \n",t2,y2);
fprintf(datafil eb,"%7.3f, %7.3f \n ", t2,y2);
t2 = t2+Dt2;
}
fclose (datafileb);
return 0;
}
Nov 14 '05 #1
3 1533
SS wrote:
It seems that my code locks my machine up after the " fclose(datafile );"
command
I guess I'm not following the next bit of code on properly.
Can someone help me out??
[ . . . ] while (t2<=Tmax2);

[ . . . ]

Remove the semicolon. By putting the semicolon there, you're saying the
while loop's body is empty (i.e., the block you have immediately after is
treated as unrelated to the while loop). Since there's nothing in the body
of the while loop to make the while condition false, the loop continues
forever.

--
Russell Hanneken
rg********@pobo x.com
Remove the 'g' from my address to send me mail.
Nov 14 '05 #2
On Thu, 5 Feb 2004 00:12:26 -0000, "SS" <we*******@srst eel.co.uk>
wrote in comp.lang.c:
It seems that my code locks my machine up after the " fclose(datafile );"
command
I guess I'm not following the next bit of code on properly.
Can someone help me out??

SS
=============== =============== =============== =============== =============== =
==========
Aside from Russell's answer, your code is not legal in any version of
standard C.
# include <stdio.h>
main ()
If you are using a compiler that conforms to the latest C99 standard,
it is illegal to define a function without a return type. This would
have to be:

int main()

....or:

int main(void)

....and is better written this way under any version of C.
{
FILE *datafile;
datafile = fopen ("a:\\lab1-1-1.csv","w");
float Dt = 0.01;
float u = 1;
float Tmax = 2;
float t = 0 , e = 0, y1 = 0, y = 0;
float J = 0.02;
float k = 10;
float B = 0.5;
while (t<=Tmax)
{
e = u - y ;
y1 = y1 +(k* Dt*e);
y = y+Dt/J*(k*y1-B*y);
printf("%7.3f %7.3f \n",t,y);
fprintf(datafil e,"%7.3f, %7.3f \n ", t,y);
t = t+Dt;
}
fclose (datafile);
//ok to here?
And if you are not using a C99 compiler, but an older one, it is
illegal to define the variable below, because all variable definitions
in a block must come before any executable code in the block.
FILE *datafileb;
datafileb = fopen ("a:\\lab1-12.csv","w");
float Dt2 = 0.01;
float u2 = 1;
float Tmax2 = 2;
float t2 = 0 , e2 = 0, y12 = 0, y2 = 0;
float J2 = 0.02;
float k2 = 1;
float B2 = 0.5;
while (t2<=Tmax2);
{
e2 = u2 - y2 ;
y12 = y12 +(k2* Dt2*e2);
y2 = y2+Dt2/J2*(k2*y12-B2*y2);
printf("%7.3f %7.3f \n",t2,y2);
fprintf(datafil eb,"%7.3f, %7.3f \n ", t2,y2);
t2 = t2+Dt2;
}
fclose (datafileb);
return 0;
}


I would suggest, whatever compiler you are using, you find the options
to tell it to compile in standard C mode.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #3
SS wrote:
It seems that my code locks my machine up
after the " fclose(datafile );" command
I guess I'm not following the next bit of code on properly.
Can someone help me out?
cat why.c # include <stdio.h>

int main (int argc, char* argv[]) {
FILE* datafile = fopen("lab1-1-1.csv", "w");
float Dt = 0.01;
float u = 1;
float Tmax = 2;
float t = 0 , e = 0, y1 = 0, y = 0;
float J = 0.02;
float k = 10;
float B = 0.5;
while (t <= Tmax) {
e = u - y ;
y1 = y1 + k*Dt*e;
y = y + Dt/J*(k*y1 - B*y);
fprintf(stdout, "%7.3f %7.3f\n", t, y);
fprintf(datafil e, "%7.3f, %7.3f\n ", t, y);
t = t + Dt;
}
fclose(datafile );
//ok to here?

FILE* datafileb = fopen("lab1-12.csv", "w");
float Dt2 = 0.01;
float u2 = 1;
float Tmax2 = 2;
float t2 = 0 , e2 = 0, y12 = 0, y2 = 0;
float J2 = 0.02;
float k2 = 1;
float B2 = 0.5;
while (t2 <= Tmax2) {
e2 = u2 - y2;
y12 = y12 +(k2* Dt2*e2);
y2 = y2 + Dt2/J2*(k2*y12 - B2*y2);
fprintf(stdout, "%7.3f %7.3f \n", t2, y2);
fprintf(datafil eb, "%7.3f, %7.3f \n ", t2, y2);
t2 = t2 + Dt2;
}
fclose(datafile b);
return 0;
}
gcc -Wall -std=c99 -pedantic -O2 -o why why.c
./why

0.000 0.500
0.010 1.125
Nov 14 '05 #4

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

Similar topics

0
1690
by: Stanley | last post by:
I have a created a report by using the Crystal Report 4.6 which is bundled with VB6. The report is connected to MS SQL Server and has 20+ fields inserted into the designer. The program stop responding after clicking the preview tab. I have done some research and found that there is a problem in CR 4.6 when selecting more than 11 fields from MS SQL Server. The problem come from the ODBC driver configuration. Is this true or anyone has...
2
2370
by: Jonathan | last post by:
Running IIS 5.0. Running both .NET and ASP pages. Every several weeks all the ASP pages stop responding. Nothing is displayed. No events show up in event logs showing that the server is having problems. .NET and static HTML pages continue to respond. Restarting the world wide web publishing service gets the asp pages responding again. Any thoughts as to what is going on?
2
5132
by: Joe A | last post by:
I'm using Access 2002 on Windows XP PC, 500 megs ram, Front end/back end app. I have a simple form that draws a thermometer to indicate progress of code that is running. The thermometer form sometimes stops advancing (does not repaint) part way thru it's cycle. If you click the MS Access window title bar during the cycle, the Access title bar switches to Access Not Responding. But if I ctrl+Break to stop the code it is indeed still...
7
1642
by: Ian Frawley | last post by:
Hello I have written some code that I can run as an app or as a service. Its role is to monitor the Process.Responding of an executing application. When it runs as an app it gets the MainWindowHandle and also detects whether the app is responding or not. However if I run my code as a Windows Service it doesn't get the MainWindowHandle and always returns true on the Process.Responding, whether it is or not. My first thought is that a...
3
1088
by: Oliver Sun | last post by:
Hi, All, After installing framework 1.1 sp1 on the win200 server where my aspnet web application located, some buttons stop responding on the aspx pages. This occurs when I access the web application using IE 6 and Windows 2000. This is an urgent problem for me. Any one can help? Thanks in advance. Oliver
14
4834
by: Anoop | last post by:
Hi, I am new to this newsgroup and need help in the following questions. 1. I am workin' on a GUI application. Does C# provides Layout Managers the way Java does to design GUI? I know that it can be done using the designer but I intentionally don't want to use that. The one reason is that you cannot change the code generated by the designer. The other could be that you have more free hand and control to design your GUI. 2....
15
2277
by: amit.man | last post by:
Hi, i have newbie qestion, when i write #include <somthing.h> the precompiler subtitue that line with the lines from "somthing.h" header file. when, where and how the compiler insert the lines in "somthing.c" implementation file into my source code?
0
1216
by: =?Utf-8?B?cGx1cG9z?= | last post by:
Hi, Problem issue 925522, http://support.microsoft.com/kb/925522/en-us (“An FTP session that is copying a file from an FTP server appears to stop responding on a client computer that is running Windows Server 2003”) is still there, FTP sessions somethimes stop ! You can find a list of updates in Windows Server 2003 Service Pack 2 on http://support.microsoft.com/kb/914962 it shows there is no fix for this issue. Conclusion might be:...
0
7934
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
7870
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
8236
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...
1
7992
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
8225
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6639
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 projectplanning, coding, testing, and deploymentwithout 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
5732
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
3891
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1199
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.