473,471 Members | 2,037 Online
Bytes | Software Development & Data Engineering Community
Create 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(datafile,"%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(datafileb,"%7.3f, %7.3f \n ", t2,y2);
t2 = t2+Dt2;
}
fclose (datafileb);
return 0;
}
Nov 14 '05 #1
3 1524
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********@pobox.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*******@srsteel.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(datafile,"%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(datafileb,"%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.learn.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(datafile, "%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(datafileb, "%7.3f, %7.3f \n ", t2, y2);
t2 = t2 + Dt2;
}
fclose(datafileb);
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
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...
2
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...
2
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...
7
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...
3
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...
14
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...
15
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...
0
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...
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
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...
1
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...
0
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.