I have written some programs in c lang yet but today I get confused
with output i get.
I have function educate(..) which i call in main program this way:
J = educate(no_laye rs, no_neurons, input, output, lay, weights, 0.1,0);
printf("J= %f\n",J);
In the educate function i count J and i return it (but before I return
it I output it with printf):
float educate (int no_layers, int no_neurons[], float input[], float
output[], float* lay[], float* weights[], float gama, int debug) {
....
printf("J= %f\n",J);
return(J);
}
This is what i get:
J= 0.304447
J= 1050402944.0000 00
Is there any syntax prob? Why the values arent the same? :(
Nov 15 '05
12 1705
On 9 Oct 2005 06:39:15 -0700, "unique" <ju*****@gmail. com> wrote: So the compiler must assume a default of educate() returning an int, which of course it doesn't.
Thank you very much Skarmander, you are completely right, i solved it with header file.
In addition to solving it this time, you should up the warning level
of your compiler so that it tells anytime you invoke a function for
which a prototype is not in scope.
<<Remove the del for email>>
unique a écrit : I was investigating the problem a bit and the problem seems to be that I call in file educate.c function educate(...) from the other file neuron.c. I dont use any include, so code is here: ***test1.c*** float educate() { float a=2.54f; printf("a= %f", a); return a; }
***test2.c*** int main(int argc, char **argv) { float b=educate(); printf("b= %f", b); }
After compiling it with: cc test1.c test2.c -lm -o test2 and running it the output is: a= 2.540000b= 1076006784.0000 00
This works fine to me (single compile unit)
#include <stdio.h>
float educate(void)
{
float a=2.54f;
printf("a= %f\n", a);
return a;
}
int main(void)
{
float b=educate();
printf("b= %f\n", b);
}
Now, if you are gooing to use 2 separated compile units (CUs), you must
define a protoype in a common file called a header. This is the proper
way of doing it:
/* educate.h */
#ifndef H_EDUCATE
#define H_EDUCATE
/* function prototypes */
float educate(void);
#endif /* guard */
Then you must include this header in the definition CU (for consistency)
and in all user CU:
/* educate.c */
#include <stdio.h>
#include "educate.h"
float educate(void)
{
float a=2.54f;
printf("a= %f\n", a);
return a;
}
/* main.c */
#include <stdio.h>
#include "educate.h"
int main(void)
{
float b=educate();
printf("b= %f\n", b);
return 0;
}
unique a écrit : I was investigating the problem a bit and the problem seems to be that I call in file educate.c function educate(...) from the other file neuron.c. I dont use any include, so code is here: ***test1.c*** float educate() { float a=2.54f; printf("a= %f", a); return a; }
***test2.c*** int main(int argc, char **argv) { float b=educate(); printf("b= %f", b); }
After compiling it with: cc test1.c test2.c -lm -o test2 and running it the output is: a= 2.540000b= 1076006784.0000 00
This works fine to me (single compile unit)
#include <stdio.h>
float educate(void)
{
float a=2.54f;
printf("a= %f\n", a);
return a;
}
int main(void)
{
float b=educate();
printf("b= %f\n", b);
}
Now, if you are going to use two separated compile units (CUs), you must
define a protoype in a common file called a header. This is the proper
way of doing it (the guard protects agains multiple inclusions in a
single CU):
/* educate.h */
#ifndef H_EDUCATE
#define H_EDUCATE
/* function prototypes */
float educate(void);
#endif /* guard */
Then you must include this header in the definition CU (for consistency)
and in all user CU:
/* educate.c */
#include <stdio.h>
#include "educate.h"
float educate(void)
{
float a=2.54f;
printf("a= %f\n", a);
return a;
}
/* main.c */
#include <stdio.h>
#include "educate.h"
int main(void)
{
float b=educate();
printf("b= %f\n", b);
return 0;
} This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Claudio |
last post by:
hi all
i put in this email source code so u can copy and paste to verify strange
first : in this example bit size is a BYTE ?!
second : in the last printf output is wrong ?
?
best regards all
|
by: LineVoltageHalogen |
last post by:
Greetings All, I was hoping that someone out there has run into this
issue before and can shed some light on it for me. I have a stored
procedure that essentially does a mini ETL from a source OLTP DB to a
the target Operational Data Store. This is still in development so
both DB's reside on the same machine for convenience. The stored proc
runs successfully from within Query analyzer and this holds true on the
following platforms: XP...
|
by: grundmann |
last post by:
Hello,
i got a strange compiler error.
When compiling the following:
// forward declarations
typedef AvlTree<LineSegment,LineSegmentComperator> LSTree;
void handleEventPoint (const EventPoint& , LSTree& , double&,
std::list<IntersectionPoint>& );
|
by: Victor Lamberty |
last post by:
Greetings C coders
I am new to the world of C and have been trying to compile this
program. I got the result that I wanted but outputed it in a strange way it
put it before the prompt is there a reason in this code. Or is that just a
trait of the KDE Konsole.
/*#I hope that this is a C program*/
/*#define hello-computer the output is hello-computer*/
#include <stdio.h>
|
by: leonecla |
last post by:
Hi everybody,
I'm facing a very very strange problem with a very very simple C
program...
My goal should be to write to a binary file some numbers (integers),
each one represented as a sequence of 32 bit.
I made this stupid trial code:
---------------------------------------------
FILE *fout;
| |
by: Martin Feuersteiner |
last post by:
Dear Group
I'm having a very weird problem. Any hints are greatly appreciated.
I'm returning two values from a MS SQL Server 2000 stored procedure to my
Webapplication and store them in sessions.
Like This:
prm4 = cmd1.CreateParameter
With prm4
|
by: soeren |
last post by:
Hello,
two days ago I stumbled across a very strange problem that came up when
we were printing tiny double numbers as strings and trying to read them
on another place. This is part of an object serialisation framework
that cannot be done in binary format currently, so please no comments
about this ,-))
It took quite some time to shrink down the problem but it looks like
that C++ does not behave well in regards to very tiny numbers.
|
by: Ian |
last post by:
Hi everyone,
I have found some bizarre (to me...!) behaviour of the Form_Activate
function. I have a form which has a button control used to close the
form and a subform with a datasheet view showing a list of jobs from
the database. When the main form loses focus and the user clicks the
'Close' button, I kept receiving error 2585 (This action cannot be
carried out whilst processing a form or report event). This was tracked
down to...
|
by: stat_holyday |
last post by:
Greetings. I'm confused. I'm attemting to create dynamic buttons based
on the count of questions in a database. The button has 3 states,
blank, selected, and inactive. The script below works great, but with a
strange bug that seems impossible to me.
When the $question_count and $question_id are 2 or more values apart
the script works, but when they are only 1 value apart, it bugs out.
Examples...
|
by: danep2 |
last post by:
Hello all
This is a really strange problem. I have code that performs a few
calculations based on input from a joystick, and writes these values
to a file using basically the following code:
fprintf(fpResults, "i: %4.2f, j: %4.2f", i, j );
This works correctly (literally) 99.9999% of the time. However, once
every million or so writes I get the following output:
|
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...
| |
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,...
|
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...
|
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,...
|
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, and deployment—without 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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
|
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...
| |