473,976 Members | 27,058 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why the excecution result changes when i try the same code on linux ?

7 New Member
I have a program (which is a university assignment) it does compile and run correctly on windows, but when i copy it an compile it on linux, it compiles and run successful but gives other results, i have been trying to figure out why for the last 10 hours and i could not ,

i have done debuging on Linux, and discovered that tere is an array of integer which values change automatically, i mean without any code that manipulaties the values,
(this unexpected change occurs only when i run on linux )
i have to deliver the assignment tommorow , it is urgent
anyone can help ?
Nov 3 '09 #1
12 1728
Ectara
24 New Member
We need more information, such as a code snippet or output, to be able to help you.
Nov 3 '09 #2
engAmrnajjar
7 New Member
thanks
the problem is that because of debugging the code in no more readable

the exercise is Knapsack problem and i have coded brutal force algorithms and the result is an array of the item which we should put in the knapsack to achieve optimal solution
so on windows it gives the right array (which yeilds the optimal solution)
on linux it does not give the same array but a random array
Nov 3 '09 #3
engAmrnajjar
7 New Member
here is the code
but it need a text input file to be executed
Attached Files
File Type: zip Code.zip (1.4 KB, 110 views)
Nov 3 '09 #4
Ectara
24 New Member
Can you provide a sample input file that is being used to test this?

And also, can you paste the output when executing this in Windows? I only run Linux on this machine.
Nov 3 '09 #5
engAmrnajjar
7 New Member
the final output of this file on windows is the array
1
0
0
1
1
1
1
1
1
1
so an item taken = 1
an item not taken = 0 ;
and here is an a simple input
and what i discovered is that there is a change in the value of the array checklist between lines
124
131
Nov 3 '09 #6
Ectara
24 New Member
Well, with the lack of the real input file, I took some liberties from what the code appears to do, and made a test file:

4
1 20 1
2 40 4
3 70 15
4 20 8
15

As you can see, with a max weight of 15, picking the first two and the last one would come out to more value than picking the third, or any other combination.

The output:
ectara@Nemesis: ~$ g++ /home/ectara/Desktop/code/temp/read_instance.c ; ./a.out test
n=4 W=15
item 1 has profit 20 and weigth 1
item 2 has profit 40 and weigth 4
item 3 has profit 70 and weigth 15
item 4 has profit 20 and weigth 8
heeeey1

4

15

8

this is checklist 0this is optList 0
this is checklist 0this is optList 0
this is checklist 0this is optList 0
this is checklist 0this is optList 0
this is CheckArray
1
1
0
1
this is the check item : 1 this is the opt Item : 0
this is the check item : 1 this is the opt Item : @@1
this is the check item : 1 this is the opt Item : 0
this is the check item : 1 this is the opt Item : @@1
this is the check item : 0 this is the opt Item : 0
this is the check item : 0 this is the opt Item : @@0
this is the check item : 1 this is the opt Item : 0
this is the check item : 1 this is the opt Item : @@1
this is the first Case
1
1
0
1
1
1
0
1


And so, my machine agrees, and states(several times) that it is logical to take the first two and the last(1) and leave the third one(0).

Despite not knowing much about what it is outputting, looks like it is working to me, assuming a 1-0-knapsack problem. Without the original test file, I can do no more than assure you that the code works on my machine, Linux 2.6.26-2-686.
Nov 3 '09 #7
engAmrnajjar
7 New Member
now i have discovered a new thing
first of all
the problem is that the program works well on visual studio
not with others even with windows (like Dev-C++)
i attached a code file in which i know the place where the problem happens but i do not know why
in line 131 for example the assignment

tempint= checklist[counter];
changes the last value of the array checklist(altho ugh it is in the left hand side of the assingment)
and here u have a real input file and the code
i really do not know why this error happens
the ouptfile is attached
and the input name is test.txt
Attached Files
File Type: zip opy.zip (1.4 KB, 66 views)
File Type: txt output.txt (5.1 KB, 398 views)
File Type: txt test.txt (198 Bytes, 396 views)
Nov 3 '09 #8
Ectara
24 New Member
Oh, those were line numbers at the end of your last post.

Hm. That is strange. The program initially has the right answer, then changes to something completely wrong. I'll take a closer look at it right now.
Nov 4 '09 #9
engAmrnajjar
7 New Member
okay i,m waiting
and thank you sooo much
Nov 4 '09 #10

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

Similar topics

0
1593
by: Bernhard Schmidt | last post by:
Hello, sorry for bothering, I'm not a programmer and I don't do much python, I'm more a networking guy trying to get his favourite linux distribution to update through the shiny new protocol IPv6 again (for those who are interested, I'm talking about Gentoo Linux) Gentoo's portage system is implemented in python calling rsync to sync with a mirror server. There are rotations (metahostnames with many address records) where portage has...
15
2695
by: Vorpal Chortler | last post by:
I've got a web customer complaining about centered text when it's not supposed to be. I just looked over at browsercam and it only appears on Win IE 6 - Nothing else, EVERYTHING else is justified left as it should be. I'm using primitive CSS1 AND tables for the site. The top page is at http://www.geocities.com/brigidregina/index.html The CSS lives at
4
3527
by: Bob Bedford | last post by:
We have no access to a mysql NG on my provider's server, so we ask here: We have a long query (long in text) with a UNION between 2 select. We have been informed that some times the query doesn't return any result. We have tried on our server and we always get a result. BUT, trying on the hosting server, many times the query doesn't return any result and doesn't get any error. Any idea ? does Union have any problem ? how to check if...
8
8254
by: Dmitri Shvetsov | last post by:
Hi All, Did somebody try to get the Hash code from byte array? The method exists, the program is compilable but...))) Try!-) Every time you can get the different code from the same array, and always very short, like in range from 10 to 18 in my case. Maybe this method has no realization? P.S. To get a correct result I use transformation of byte to string and
9
2924
by: | last post by:
void show( char *s, ...) is a function seemd like prinf code -------------- #include <stdio.h> #include <stdarg.h> void show( char *s, ...) { va_list stage;
9
3231
by: Tim D | last post by:
Hi, I originally posted this as a reply to a rather old thread in dotnet.framework.general and didn't get any response. I thought it might be more relevant here; anyone got any ideas? My questions are below... "David Good" wrote: > We have a network running both Win2k and Win2k3 webservers and our web sites > reside on a UNC network share that happens to be a Network Appliance NAS.
2
2104
by: mrashidsaleem | last post by:
Using the SQL 2005 "query notification" caching mechanism, I am caching three columns (UserId, UserName, Password) of a table called UserInfo in my web application cache. However, the cache gets invalidated (and needs to be re-loaded) when another column LastUpdateDateTime of the same table gets modified. This is NOT as per my expectation. Following is what MSDN says about Query Notifications in SQL2005...
0
1282
by: ajitkathar | last post by:
In my SQLJ procedure , there is call to another stored procedure using a callable statement. But during excecution when .excute() happens . . the DB2 V7 database shuts down. Plz help. Follwing is the code . . ************ CAL02RSCAL.sqlj which call another PL/SQL Strored procedure TESTRSFILEPL written in DB2 ******************* package PAKCAL02RSCAL ; import java.sql.*;
5
2936
by: bmm | last post by:
I have a Store Procedure on a Sql Server 2000 Where I use the Table Hint "NoLock" on all selects. One of my clients (OleDbConnection from C#) doesn't get the same Result Set as the others. The result Set should have 31 rows but this client only gets 5! When I remove all the "NoLocks" everything works fine. How can that be?
0
10349
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, 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...
0
11405
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 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...
1
11567
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
10903
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
10080
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, 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...
1
8454
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
7601
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6412
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
5149
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 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.