Hello, Cananyone help me. I wrote a c code and this code supposed to classify network traffic into two classes but I used a bayesian classifier implementation but it is generating errors like network_traffic2.c:11: error: `main' must return `int' This is the code below: Code: #include <string> #include <iostream> #include "includes/smile.h" #include "includes/network.h" void main() { DSL_network theNet; // The Bayesian network DSL_stringArray someNames; // String array used by libraries DSL_stringArray * theNames; DSL_doubleArray theProbs; // Array of doubles used to store probabilities DSL_sysCoordinates theCoordinates; // int intrusion; // Contains ID number for intrusion node int traffic; // Contains ID number for traffic node int alarm; // Contains ID number for alarm node int Packet_size; // Contains ID number forPacket size node (jim) int TCP_por_info; // Contains ID number for Traffic info request node (mary) int true_value; // Contains ID number for true value of node int false_value; // Contains ID number for false value of node double current_belief; intrusion = theNet.AddNode(DSL_CPT, "Intrusion"); someNames.Flush(); // Empty string array someNames.Add("True"); // First Value someNames.Add("False"); // Second Value theNet.GetNode(intrusion) -> Definition() -> SetNumberOfOutcomes(someNames); traffic = theNet.AddNode(DSL_CPT, "Traffic"); someNames.Flush(); // Empty string array someNames.Add("True"); // First Value someNames.Add("False"); // Second Value theNet.GetNode(traffic) -> Definition() -> SetNumberOfOutcomes(someNames); alarm = theNet.AddNode(DSL_CPT, "Raise Alarm"); someNames.Flush(); // Empty string array someNames.Add("True"); // First Value someNames.Add("False"); // Second Value theNet.GetNode(alarm) -> Definition() -> SetNumberOfOutcomes(someNames); Packet_size = theNet.AddNode(DSL_CPT, "Packet size"); someNames.Flush(); // Empty string array someNames.Add("True"); // First Value someNames.Add("False"); // Second Value theNet.GetNode(Packet_size) -> Definition() -> SetNumberOfOutcomes(someNames); TCP_por_info = theNet.AddNode(DSL_CPT, "TCP Port information"); someNames.Flush(); // Empty string array someNames.Add("True"); // First Value someNames.Add("False"); // Second Value theNet.GetNode(TCP_por_info) -> Definition() -> SetNumberOfOutcomes(someNames); theNet.AddArc(intrusion, alarm); // Add arc from intrusion to Alarm theNet.AddArc(traffic, alarm); // Add arc from traffic to Alarm theNet.AddArc(alarm, Packet_size); // Add arc from Alarm to Packet_size theNet.AddArc(alarm, TCP_por_info ); // Add arc from Alarm to TCP_por_info theProbs.SetSize(2); theProbs[0] = .001; theProbs[1] = .999; theNet.GetNode(intrusion) -> Definition() -> SetDefinition(theProbs); theCoordinates.LinkTo(*theNet.GetNode(traffic) -> Definition()); theCoordinates.UncheckedValue() = .002; theCoordinates.Next(); theCoordinates.UncheckedValue() = .998; theCoordinates.Next(); theCoordinates.LinkTo(*theNet.GetNode(alarm) -> Definition()); theCoordinates.UncheckedValue() = 0.95; // I, T, A theCoordinates.Next(); theCoordinates.UncheckedValue() = 0.05; // I, T, ~A theCoordinates.Next(); theCoordinates.UncheckedValue() = 0.94; // I, ~T, A theCoordinates.Next(); theCoordinates.UncheckedValue() = 0.06; // I, ~T, ~A theCoordinates.Next(); theCoordinates.UncheckedValue() = 0.29; // ~I, T, A theCoordinates.Next(); theCoordinates.UncheckedValue() = 0.71; // ~I, T, ~A theCoordinates.Next(); theCoordinates.UncheckedValue() = 0.001; // ~I, ~T, A theCoordinates.Next(); theCoordinates.UncheckedValue() = 0.999; // ~I, ~T, ~A theCoordinates.Next(); theCoordinates.LinkTo(*theNet.GetNode(Packet_size) -> Definition()); theCoordinates.UncheckedValue() = 0.9; // A, Packet_size theCoordinates.Next(); theCoordinates.UncheckedValue() = 0.1; // A, ~Packet_size theCoordinates.Next(); theCoordinates.UncheckedValue() = 0.05; // ~A, Packet_size theCoordinates.Next(); theCoordinates.UncheckedValue() = 0.95; // ~A, ~Packet_size theCoordinates.Next(); theCoordinates.LinkTo(*theNet.GetNode(TCP_por_info) -> Definition()); theCoordinates.UncheckedValue() = 0.7; // A, TCP_por_info theCoordinates.Next(); theCoordinates.UncheckedValue() = 0.3; // A, ~TCP_por_info theCoordinates.Next(); theCoordinates.UncheckedValue() = 0.01; // ~A, TCP_por_info theCoordinates.Next(); theCoordinates.UncheckedValue() = 0.99; // ~A, ~TCP_por_info theCoordinates.Next(); theNet.WriteFile("taiwo_traffic.dsl"); theNet.SetDefaultBNAlgorithm(DSL_ALG_BN_LAURITZEN); // Sets algorithm used to solve net theNet.UpdateBeliefs(); // Has net go through and calculate current belief // Find starting belief that Packet_size will be detected and raise theCoordinates.LinkTo(*theNet.GetNode(Packet_size) -> Value()); theNames = theNet.GetNode(Packet_size) -> Definition() -> GetOutcomesNames(); true_value = theNames -> FindPosition("True"); // Should always be 0 false_value = theNames -> FindPosition("False"); // Should always be 1 theCoordinates[0] = true_value; theCoordinates.GoToCurrentPosition(); current_belief = theCoordinates.UncheckedValue(); printf("Starting belief that there is no %f\n", current_belief); // Find starting belief that TCP_por_info show no intrusion theCoordinates.LinkTo(*theNet.GetNode(TCP_por_info) -> Value()); theCoordinates[0] = false_value; theCoordinates.GoToCurrentPosition(); current_belief = theCoordinates.UncheckedValue(); printf("Starting belief that TCP_por_info show no intrusion is %f\n", current_belief); // Find starting belief that an intrusion is happening theCoordinates.LinkTo(*theNet.GetNode(intrusion) -> Value()); theCoordinates[0] = true_value; theCoordinates.GoToCurrentPosition(); current_belief = theCoordinates.UncheckedValue(); printf("Starting belief that a intrusion is happening is %f\n", current_belief); // Repeat, this time with traffic set to true theNet.GetNode(traffic) -> Value() -> SetEvidence(0); theNet.UpdateBeliefs(); theCoordinates.LinkTo(*theNet.GetNode(Packet_size) -> Value()); theCoordinates[0] = 0; // Notice the change from true_value to 0 theCoordinates.GoToCurrentPosition(); current_belief = theCoordinates.UncheckedValue(); printf("Belief that Packet_size will raise alarm if traffic happens is %f\n", current_belief); theCoordinates.LinkTo(*theNet.GetNode(TCP_por_info) -> Value()); theCoordinates[0] = 1; // Notice the change from false_value to 1 theCoordinates.GoToCurrentPosition(); current_belief = theCoordinates.UncheckedValue(); printf("Belief that TCP_port_info does not have intrusion is %f\n", current_belief); theCoordinates.LinkTo(*theNet.GetNode(intrusion) -> Value()); theCoordinates[0] = true_value; theCoordinates.GoToCurrentPosition(); current_belief = theCoordinates.UncheckedValue(); printf("Belief that a intrusion is happening during an traffic is %f\n", current_belief); // Repeat, this time with alarm set to true theNet.GetNode(traffic) -> Value() -> ClearEvidence(); theNet.GetNode(alarm) -> Value() -> SetEvidence(0); theNet.UpdateBeliefs(); theCoordinates.LinkTo(*theNet.GetNode(Packet_size) -> Value()); theCoordinates[0] = 0; theCoordinates.GoToCurrentPosition(); current_belief = theCoordinates.UncheckedValue(); printf("Belief that Packet_size will raise alarm if there is intrusion is %f\n", current_belief); theCoordinates.LinkTo(*theNet.GetNode(TCP_por_info) -> Value()); theCoordinates[0] = 1; theCoordinates.GoToCurrentPosition(); current_belief = theCoordinates.UncheckedValue(); printf("Belief that TCP_port_info will not raise alarm if intrusion happens is %f\n", current_belief); theCoordinates.LinkTo(*theNet.GetNode(intrusion) -> Value()); theCoordinates[0] = true_value; theCoordinates.GoToCurrentPosition(); current_belief = theCoordinates.UncheckedValue(); printf("Belief that an intrusion is happening when alarm goes off is %f\n", current_belief); // Now set traffic to true theNet.GetNode(traffic) -> Value() -> SetEvidence(0); theNet.UpdateBeliefs(); theCoordinates.LinkTo(*theNet.GetNode(Packet_size) -> Value()); theCoordinates[0] = 0; theCoordinates.GoToCurrentPosition(); current_belief = theCoordinates.UncheckedValue(); printf("Belief that Packet_size will raise alarm if the intrusion happens is %f\n", current_belief); theCoordinates.LinkTo(*theNet.GetNode(TCP_por_info) -> Value()); theCoordinates[0] = 1; theCoordinates.GoToCurrentPosition(); current_belief = theCoordinates.UncheckedValue(); printf("Belief that TCP_port_info will not raise alarm intrusion happens is %f\n", current_belief); theCoordinates.LinkTo(*theNet.GetNode(intrusion) -> Value()); theCoordinates[0] = true_value; theCoordinates.GoToCurrentPosition(); current_belief = theCoordinates.UncheckedValue(); printf("Belief that a intrusion is happening with alarm and earthquake true is %f\n", current_belief); } DaWei -- repaired code tags.
Your code tags are incomplete. I will fix them for you, this time. Your problem is that main is defined, by the standard, to return an int. Some less-than-compliant compilers will accept other forms. It seems that yours does not. Therefore, change your definition.
Thanks alot. I have checked the code, I appreciate it. But it does not complain of any error from the main (). Thanks alot. I appreciate it. So, how can I put the code into the Code: Can you explain it to me. Cheers.
The only error you mentioned was from main. That has been explained. You have not asked any other complete question, nor given any information, nor stated your expectations and how they are not being met. Please read the entire "Before you make a query" thread.
DaWei just corrected the code tags and not the code and if your compiler is not complaining now it should not have complained before as well.
Thanks, I have corrected the code by changing void main () to Int main (), but it is now generating Linker error..I mean it cannot link to the libaries... I have compiled the code but there is a problem with the LINK...Is there any other way to create a link or use other libraries. I am using smile: smile.lib and this is usually used for Bayesian classifier...Is there any other libaries that I can use? The Link error are: Linking... smile.lib(errorstrings.obj) : warning LNK4078: multiple ".CRT" sections found with different attributes (40300040) libcpd.lib(locale0.obj) : error LNK2005: "public: static unsigned int const std::ctype<char>::table_size" (?table_size@?$ctype@D@std@@2IB) already defined in smile.lib(network.obj) LINK : warning LNK4098: defaultlib "LIBCMT" conflicts with use of other libs; use /NODEFAULTLIB:library smile.lib(expressiontree.obj) : error LNK2001: unresolved external symbol "public: __thiscall std::exception::exception(char const * const &)" (??0exception@std@@QAE@ABQBD@Z) smile.lib(helementarray.obj) : error LNK2001: unresolved external symbol "public: __thiscall std::exception::exception(char const * const &)" (??0exception@std@@QAE@ABQBD@Z) There are more but this is just some of them.... Can anyone help... Thanks
How can I compile c ++ code with the library on Linux? This does not work: c++ -L network.cpp - lsmile Cheers.