Same C++ code gives different result in MacOSX and Ubuntu

Hi
I have a C++ program which starts by reading an external file, but changing the name of the file give me different results.
I selected just the important part and made a simple file with the reading part of my program and can be downloaded here
http://dl.dropbox.com/u/664351/files.zip
It just reads the external file and does the output of some values.
It has two external file examples. If one uses "x.txt" everything works fine, but if we use "dados.txt", which is a copy of "x.txt", the last value in the output is wrong.
The stranger is that if i use these same files in ubuntu everything works just fine!
I tried in a MacBook, a MacBook Pro and an iMac (all of them with macosx 10.6) and i always got the error, but not on ubuntu!
Does anyone has a clue about what is happening here?
Cheers,
Marcelo

marcelobarbosa wrote:
Does anyone has a clue about what is happening here?
Change OutFile from a 20 byte character array to a string. GCC isn't able to tell what type that is and is picking int or something, corrupting your memory.

Similar Messages

  • Same gui code 2 different results in xp and 7

    First Machine:Xp,netbeans 6.8, jdk 6 update 19(upgraded due to that problem)
    Second Machine:7,netbeans 6.7.1, jdk 6 update 17
    Image1: http://img686.imageshack.us/img686/5781/gui1.jpg
    Image2: http://img30.imageshack.us/img30/3751/gui2y.jpg
    Here is the code:
    public class MyFrame extends JFrame{
    public Point point1;
    public Point point2;
    private ImageIcon imc;
    private ImageIcon imc2;
    private final Color c1 = Color.green;
    private final Color c2 = Color.cyan;
    private final Color c3 = Color.yellow;
    private final Color c4 = Color.red;
    public MyFrame(Point p1,Point p2,String filename1,String filename2){
    super("xxx");
    imc = new ImageIcon(filename1);
    imc2 = new ImageIcon(filename2);
    point1 = p1;
    point2 = p2;
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JLabel emptyLabel = new JLabel("");
    emptyLabel.setPreferredSize(new Dimension(850,650));
    getContentPane().add(emptyLabel, BorderLayout.CENTER);
    //Display the window.
    pack();
    setVisible(true);
    @Override
    public void paint(Graphics g){
    g.setColor( c2 );
    g.fillRect(50, 100, 750, 500);
    g.setColor( c1 );
    g.fillRect( 150, 200, 550, 300 );
    g.setColor( c3 );
    g.drawRect( 100, 150, 650, 400 );
    g.setColor( c4 );
    g.drawLine( 425, 500, 425, 600 );
    imc.paintIcon(this, g, point1.x, point1.y);
    imc2.paintIcon(this, g, point2.x, point2.y);
    }Any solution for that?
    Thanks in advance.
    Edited by: kapodistrias on Mar 31, 2010 12:06 AM

    Really thanks.
    But I think if I had not run it in another machine I would have thought that it was right.
    I have done all the backround but I still cannot add the 2 image icons.
    I tried these inside the jpanel after the background but it seems they don't work.
    Image imc3 = imc.getImage();
    g.drawImage(imc3, point1.x, point1.y, this);
    or
    imc.paintIcon(mypanel, g, point1.x, point1.y);
        public class MyPanel extends JPanel{
            public MyPanel(){
                add(new JLabel(""), BorderLayout.CENTER);
                this.setBackground(c1);
            @Override
            public void paintComponent(Graphics g){
                super.paintComponent(g);
                g.setColor( c2 );
                g.fillRect(50, 100, 750, 500);
                g.setColor( c1 );
                g.fillRect( 150, 200, 550, 300 );
                g.setColor( c3 );
                g.drawRect( 100, 150, 650, 400 );
                g.setColor( c4 );
                g.drawLine( 425, 500, 425, 600 );
                Image imc3 = imc.getImage();
                g.drawImage(imc3, 0, 0, this);
                //imc.paintIcon(mypanel, g, point1.x, point1.y);
                //imc2.paintIcon(mypanel, g, point2.x, point2.y);
        }

  • Same code gives different results in Matlab Script in Labview and Matlab

    I am implemeting a Matlab code into a LabVIEW application using Matlab script. When I import the exactly same code to the Matlab Script in LabVIEW it gives a different result than it is in Matlab. This code is a simulation code including first kind bessel functions. Using LabVIEW 7.1 and Matlab R14 service pack 3.

    Labview 8.5
    Matlab R2009b
    Attached are the graphs produced by matlab script in labview and in matlab.
    The minimum of graph produced by matlab code is below 1 and that in labview is above 1.
    Thanks a lot for your reply.
    Sorry, I haven't quantified the "sometimes" yet. 
    Attachments:
    matlabsResult.jpg ‏29 KB
    LV.png ‏84 KB

  • Same exact Code but different results

    I am trying to fill a Listbox in a single Dialog based program using names
    from a file. I started by using an example program from the MSDN - Modeless.
    A simple Dialog based program using a modeless dialog to add strings to a
    Listbox in the main dialog. I inserted into the sample program the following
    code, which works perfectly:
    #include <Fstream>
    BOOL CLeasesDlg:nInitDialog()
    char* names;
    CListBox* pList = (CListBox*) GetDlgItem(IDC_LIST);
    infile.open("Leases",ios::in, filebuf:penprot);
    while( (infile.getline(names,25,'\n')) != NULL)
    pList->AddString(names);
    infile.close();
    Sunce the sample program was just a stepping stone I created my own Dialog
    based program using the AppWizard. I inserted the above code. I now receive
    an "unhandled exception" error every time during the "getline" execution. I
    have been trying for the last several days to track down the problem but can
    not.
    Some of what I learned:
    First-chance exception in Leases.exe (MSVCIRTD.DLL): 0xC0000005: Access
    Violation.
    so I wrote code to establish access permissions:
    int test = 0;
    // Check for existence
    if( test = ((_access( "Leases", 0 )) != -1) )
    // Check for read permission
    if(test = ((_access( "Leases", 4 )) != -1) )
    I stepped thru both with no problem. The file exist and is readable but can
    not retreive the first name.
    In the disassembly window it stops on this line:
    strgetl.cpp --------------------------------------------------------------
    102A75CD 88 08 mov byte ptr [eax],cl
    I do not understand how the code can work in the sample program and not work
    in the one I created. I looked back at another program I wrote several years
    ago and I used the exact same code with no problem. I would think that my
    compiler was corrupted but it compiles the modeless sample program.
    I am totally baffled .... PLEASE ... PLEASE help!
    I would be greatly appreciative

    Hey Randy,
    This forum is reserved for Measurement Studio questions.  I recommend checking with Microsofts forums because the people there will have more experience doing what you are looking for. 
    Regards,
    jigg
    CTA, CLA
    teststandhelp.com
    ~Will work for kudos and/or BBQ~

  • Same float code compiled differently on different machines

    Hi,
    Scenario:   same project build on different machines. and then both the  application executed on
    same machine .. giving  slightly different results..(like 23.07499   to 23.07500)
    project involves many float operations.  project build on vs2013. c++
    there is difference oberved in the final value of float calculations..  like 23.07499   to 23.07500
    seems , Same float code compiled differently on different machines,  any input
    Regards,
    james

    >Scenario:   same project build on different machines. and then both the  application executed on same machine ..
    giving  slightly different results..(like 23.07499   to 23.07500)
    Do you get consistent results with the same executable each time you
    run it?
    Assuming you do, and the only difference is the EXEs, what's the
    difference between them - there must be something. Have a look at "How
    to compare binary images of the same project builds"
    https://support.microsoft.com/en-us/kb/164151/ and see if that sheds
    any light onto the issue.
    Dave

  • Do IMAQ Cast Image or IMAQ Linear averages give different results when using different computers that are running under Windows XP ?

    Hello
    I'm currently developping an image processing algorithm using Labview 7.1 and the associated IMAQ Vision tools. After several tests, I found a weird result. Indeed, I put the labview algorithm - including the IMAQ VI on the library to get sure that I use all the time the same VI - on my memory stick and used it on two different computers. I tested the same picture (still in my memory stick) and had two very different results.
    After several hours trying to understand why, I found that there were a difference between the results given by both computers at the very begining of the algorithm. Indeed, I used a JPEG file.
    To open it, I first create an Image with IMAQ Create (U8). Then, I open it.
    Then in my first sub-VI, I use IMAQ Cast Image to be sure that the picture is a U8 grayscale picture.
    Right after that, I use the IMAQ Linear Averages. The results of this VI are different on the two computers.
    I tried several time on the same picture : one computer always give me the same result but the two computers give me a different result. So there is no random variable on the results.
    So my question is : Do IMAQ Cast Image or IMAQ Linear averages give different results when using different computers that are running under Windows XP ?
    My bet is on IMAQ Cast Image but I'm not quite sure and I do not undestand why. The labview and IMAQ are the same on both computers.
    The difference between the two computer are above :
    Computer 1 :
    Pentium(R) 4 CPU 3.20GHz with a RAM of 1Go. The processor is an Intel(R).
    The OS is windows XP Pro 2002
    Computer 2 :
    Pentium(R) 4 CPU 2.80GHz with a RAM of 512Mo. The processor is an Intel(R).
    The OS is windows XP Pro 2002.
    If anybody can help me on this problem, it would be really helpful.
    Regards
    Florence P.

    Hi,
    Indeed it's a strange behaviour, could you send me your VI and your JPEG file, (or another file that reproduces) so that I could check this inthere ?
    I'll then try to find out what's happening.
    Regards
    Richard Keromen
    National Instruments France
    #adMrkt{text-align: center;font-size:11px; font-weight: bold;} #adMrkt a {text-decoration: none;} #adMrkt a:hover{font-size: 9px;} #adMrkt a span{display: none;} #adMrkt a:hover span{display: block;}
    >> Découvrez, en vidéo, les innovations technologiques réalisées en éco-conception

  • Different result in IE and Netscape

    Hi,
    I am using JDeveloper 3.2 to create my JSP and BC4J. I deployed them into my web server, but I got different result in IE and Netscape. I amd using web bean method to create my JSP.
    When I view my JSP from IE, everything looks as expected. But when I view them from Netscape, some pages did not display correctly.
    1. For the JSTab, the Netscape displays different color(blue) in the help text area, but the IE display gray color.
    2. If I have a table with many columns (e.g.25) to be displayed and my browser is too small to display them all, the Netscape displays JSRowSetBrowser incorrectly. The top right corner, and bottom right corner did not display at the last column side, instead it displaying in the middle of my JSRowSetBrowser. It also suppressed my one button in the same page. IE displays them all properly.
    How do I fix this problem? Please help.
    I am using webapp/cabo/images/cabo_styles.css as my style sheet.
    Lisa
    null

    I'm not an expert on Netscape, but I would guess that you're problems are simply caused by the differences between IE and NS.
    It is very difficult to write (functional) JS code that works perfectly between the two of them and I bet that JSTab isn't written in such a way.
    You may want to try using your own tab object, we do this by creating a page for each tab and making the actual tabs be links to each page. This avoids the use of JavaScript.
    Good Luck!!!

  • Same calculation producing two differing results

    Hi All
    I have some code in a user exit on save of a delivery (VL02N) that calculates the number of bags/pallets required to furnish that delivery.
    I am now adding the same code to a user exit on save a sales order (VA02) to calculate the number of bags/pallets again but when run it is producing differing results.
    the code is as follows:
    DATA: bag_weight(12) TYPE p DECIMALS 4.
    DATA: pallet_weight TYPE marm-umrez.
    DATA: bag_denominator TYPE i.
    bag_weight = pallet_weight / bag_denominator.
    Assuming pallet_weight = 1000 and bag_denominator = 40.
    On save of a delivery it is calculating bag_weight as 25.0000 (correct):
    On save of a sales order it is calculating bag_weight as 0.0025 (incoorect).
    All data declaration, code etc is the same. Does anybody have any clue as to why it would give two differing answers, I would not like to have to add a additional multiplication step to correct the result otherwise.
    Thanks in advance
    David

    Hi,
    Whenever you are using the Packed numbers, you need to check or set the program attribute fixed point arithmetic only as only this ensure that the decimal point is calculated correctly.
    Have a look at the help.sap.com documentation link:
    http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb2fd9358411d1829f0000e829fbfe/content.htm
    Hope this helps.
    Thanks,
    Samantak.

  • P/L A/c for a single day gives different results for different users

    Hi!
         We have SAP B1 8.81 (PL 09) in our office. P/L Account for a particular date gives different value for a single account (Other Income Account) for one user and a consistent value for all other users. The user in question is a super user and does not seem to pick a specific entry posted in the Other Income Account for that day thus giving erroneous result. I have checked the Trial Balance for that day and it gives proper result. Only the P/L account gives erroneous data. Could anyone help with the reason for this.
    Thanks
    Sreekumar

    Hi Jitin,
              Thanks for your reply.
              I tried the way you mentioned. However, the result is the same.
              The entry that I'm talking about is an automatic journal entry posted through the Outgoing Payment option.
              To make it more clear, an outgoing payment to a vendor was posted on 05/19/11 for 1,42,178.32. The check was drawn only for 71,089.16 which was the correct amount and the remaining amount (71,089.16) got posted in the Other Income account. The P/L account for this date is not picking the amount of 71,089.16 in the Other Income Account.
    Thanks & Regards
    Sreekumar
    Edited by: Sreekumar on Jan 31, 2012 5:58 PM

  • Why not exists and minus give different result

    HI,
    I am writing thes query by using two different operators they should give me the same output but they dont. Please can anybody explain why they give different output.
    query 1
    SQL> SELECT COUNT(*) FROM
    2 (select orig_idx
    3 from rel15_au_poi a
    4 MINUS
    5 SELECT ORIG_IDX
    6 FROM REL14_1_AU_POI_INTERM B) ;
    COUNT(*)
    244312
    query 2
    SQL> select count(*)
    2 from rel15_au_poi a
    3 where not exists
    4 (select null from rel14_1_au_poi_interm b where a.orig_idx=b.ORIG_IDX) ;
    COUNT(*)
    245341
    best Regards,

    Because you have duplicates in rel15_au_poi which are counted with exists and removed with minus.
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries004.htm#sthref3147
    MINUS Example
    The following statement combines results with the MINUS operator, which returns only unique rows returned by the first query but not by the second:
    SELECT product_id FROM inventories
    MINUS
    SELECT product_id FROM order_items;

  • Same circuit twice with different results

    I've been having some trouble having Multisim match a circuit I have modeled in MATLAB. During the troubleshooting process I put voltage probes on each wire used. The circuit portion in question involves an AC Voltage source connected to a resistor which is then connected to an inductor. I made a copy of the circuit and started from scratch. One of the circuits gives a voltage drop across the resistor, while the other one doesn't drop any voltage at all. I've checked all of the connections and they are all good. The only difference I can see is that one has the pins labeled 1 - 2 while the other is 2 - 1. Does anyone know what the problem is here? I shouldn't not be getting two different results for the same circuit.

    Hi Jmerc,
    Maybe you can post the circuits so that we can compare.
    Tien P.
    National Instruments

  • Same Effects Panel parameters-different results on Tiff & Psd file format?

    Just a quick question to all the users and the Adobe Lightroom team & see if anybody has the same problem.
    I have one file saved in a Tiff format & the exact duplicate saved in a PSD, however when I sync the Effects Panel settings between the two, I get different results. The difference isn't black & white but clearly visible. The grain in the PSD file is less coarse & pronounced and the post crop vignetting is much more subtle. The color balance is also different. In other words every adjustments seems to be more subtle & less pronounced on a PSD file compare to a Tiff file.
    Not the end of the world but clearly something to keep in mind when syncing settings between the two formats and something that shouldn't be there in the first place.
    Thanks

    Now you are providing more detail.
    "... but lesser quality at least in terms of natural movement."
    It sounds very much like 11 is exporting 25p/30p which is why you see non smooth motion.
    25p/30p is the result of deinterlacing 50i/60i. When you take two FIELDS that are 1/50th or 1/60th apart and create 1 image, these images will be 1/25th or 1/30th second apart.
    You can create 1 frame through several methods.
    With iM09 deinterlacing occured only if you imported as LARGE, OPTIMIZED video, or used a function or FX that scales video. Perhaps with 11, Apple has decided that its time to FORCE any kind of interlaced video to be deinterlaced.
    In other words, LARGE and FULL only relate to size.
    One possible advantage is that Apple has finally decided to deinterlace using BLEND during import. This would look better, but it creates 25p or 30p video.
    They may hinting its time to buy a progressive camera.

  • Query via linked server to DB2/NT gives different results

    I have a DB2 9.7 database I need to query. I'm testing from four separate SQL Servers.
    ServerA - SQL 2012 SP2
    ServerB - SQL 2012 SP1
    ServerC - SQL 2012 SP1 CU1
    ServerD - SQL 2012 SP1
    I set up a linked server from ServerA. I run QueryA, and am happy with the results.
    I create a linked server from ServerB. I run QueryA and get the message, "Error converting data type DBTYPE_DBDATE to datetime."
    I did the same test on ServerC. It works fine.
    If, inside OPENQUERY, I convert the datetime to a varchar, call it QueryB, it mostly works, but will be missing a small percentage of datetime values from that converted column when run on ServerB. If I run QueryB on the on ServerA, those missing
    values are there. Same for ServerC.
    At this point, I can think only that the main difference is the service pack and CU level. I can't find any documentation on updates that are relevant, but doesn't mean much.
    Then, I did the same test on ServerD. ServerD is at the same SP/CU level as ServerB. ServerD worked just fine. Apparently it's not the service pack or cumulative update level making the difference.
    My setup: On each server I loaded MS OLE DB Provider for DB2 Version 4.0. I used the same sp_addlinkedserver script with the same connection string on each server. QueryA and QueryB both used OPENQUERY. They were identical except for the CAST to varchar
    for a datetime field. This CAST became a call to a function VARCHAR on the DB2 server in later tests with the same result. 
    Of course, the only place I actually need this working is ServerB.
    tia,
    Steve

    Sure, with some obfuscation and shortening.
    On each server, (except the first where I had to figure it out), I went through the same process.
    Load MS OLE DB Provider for DB2 Version 4.0 version 9.0.1390.0
    Run the Create Linked Server query
    Run QueryA.
    Only on ServerB has this been a problem. 
    --Create Linked Server
    EXEC sp_addlinkedserver
    @server='LinkedServer',
    @srvproduct='Microsoft OLE DB Provider for DB2',
    @catalog='DBName',
    @provider='DB2OLEDB',
    @provstr='Provider=DB2OLEDB;User ID=Username;Password=Password;Initial Catalog=DBName;Network Transport Library=TCPIP;Host CCSID=1252;PC Code Page=1252;Network Address=127.0.0.1;Network Port=50000;Package Collection=MSDB2COL;Process Binary as Character=False;Units of Work=RUW;DBMS Platform=DB2/NT;Use Early Metadata=False;Defer Prepare=False;DateTime As Char=False;Rowset Cache Size=0;Datetime As Date=False;AutoCommit=True;Authentication=Server;Decimal As Numeric=False;Derive Parameters=True;LoadBalancing=False;Persist Security Info=True;Cache Authentication=False;Mode=Read;Connection Pooling=False;'
    --QueryA
    SELECT * FROM OPENQUERY(LinkedServer,'
    SELECT [ARRIVAL]
          ,[ACCT_CODE]
          ,[ACC_EVENT_ID]
          ,[TRANS_DATET]
          ,[AVAIL_DATE]
          ,[AVAIL_STATUS]
      FROM [DBName].[UserName].[TableName]
    ') AS TableNameLink
    --QueryB
    SELECT * FROM OPENQUERY(LinkedServer,'
    SELECT [ARRIVAL]
    ,[ACCT_CODE]
    ,[ACC_EVENT_ID]
    , CAST([TRANS_DATET] AS VARCHAR(26)) TRANS_DATET
    ,[AVAIL_DATE]
    ,[AVAIL_STATUS]
    FROM [DBName].[UserName].[TableName]
    ') AS TableNameLink
    --QueryC
    SELECT * FROM OPENQUERY(LinkedServer,'
    SELECT [ARRIVAL]
    ,[ACCT_CODE]
    ,[ACC_EVENT_ID]
    , VARCHAR([TRANS_DATET]) TRANS_DATET
    ,[AVAIL_DATE]
    ,[AVAIL_STATUS]
    FROM [DBName].[UserName].[TableName]
    ') AS TableNameLink

  • Matlab 'place' command gives different result in Mathscript/Labview

    Hello,
    I am trying to implement a order reduced observer in Labview. First I used Labview blocks for programming but it happens that I get different results when I am using Matlab. For that reason I used Mathscript to make a simple 'place' command to check it. The result in Labview and Mathscript is the same, but not in Matlab...
    This is the instruction in Matlab:
    A22=[0.9024 0 0;0 0.8607 0; 0 0 0];
    A12=[0 0 0 ;0 0 0.0548;0.0417 0 0;0 -0.0417 0];
    K=place(A22',A12',[0.32 0.31 0.3]);
    Ko=K'
    Ko =
             0         0   13.9664         0
             0         0         0  -13.2062
             0   -5.4745         0         0
    And I have attached the VI where I do the test with Labview blocks and Mathscript. As you can see the result is not even close to be similar. Why is this produced? How can I fix it?
    Thank you a lot in advance!
    Attachments:
    pruebararamathscript.vi ‏39 KB

    Hi,
    Indeed there are a lot of gains that places the poles on the desired locations. BUT, seeing as the Varga's SEAP algorithm is implemented, the G matrix is selected through a uniform white noise generator and the desired characteristics are verified (controllability). This does not unsure optimization regarding stability margins or disturbance rejection (sensitivity minimization regarding perturbations an matrix A or B).
    As an example, the system presented in this thread, the algorithm implemented in CD Pole Placement.vi computes an observer gain that determine a 7,4455 value for closed loop infinity norm. The place algorithm in Matlab computes an observer gain that determine a 2,8230 value for closed loop infinity norm, so better noise rejection or robustness.
    cosmin

  • Interactive Reporting Reports - Same Rpt Format, but Different Result Set

    I have created a report using result set 1. I've saved that, but want to copy it & use the same format/columns to create a new report using a different result set (the result sets have the same data, but one is filtered). Is there an easy way to change the name of the result set being used w/o re-creating the entire report columns & all?
    Terri

    I am in the Dashboard Studio - Optimize Utility. When I select that report (or any of the others), the Reparent button is grayed out on the toolbar. I've also tried right-clicking on the report and it's grayed out there as well. Any ideas?

Maybe you are looking for

  • How do I connect Airport Extreme and Time Capsule to my new iMac so that AE is used for network and TC only used for Time Machine backup?

    I didn't realize that Time Capsule will only support the print function of a wireless multifunction printer.  So I want to use Extreme for my network to have full use of my printer and use TC as the Time machine backup only.  How to I make the connec

  • Windows will not recognize ipod touch also says it has malfunctioned

    hi whenever i plug in my ipod touch i get a message saying that "usb device not recognized, one of the usb drives attached has malfunctioned and windows cannot recognize it" i have reinstalled itunes 8.1 twice the second time i reinstalled the apple

  • Photoshop CS4 Extended    Vista

    Customer Notes: Photoshop CS4 on 64 bit will only print a thumbnail,but on 32 bit it works fine.  Reinstalled drivers, no change.  print drivers are running from \windows\system32\spool\drivers\x64\.  All other programs 32/64 bit print without issue.

  • Strange behavior of workflow

    hi Experts, Is this the expected behavior of WCC workflow? 1. user1 created a doc named doc1, this doc match condition for workflow1, and status is "review" 2. user1 checkout doc1 and checkin(as doc1 is in review status, checkin action should be proh

  • Photo synching issue

    When I am synching my iPhone through iTunes. I always get the same error message that reads: "Itunes cannot sync photos to the iPhone because the folder "Pictures" cannot be found." I am not sure resolving this issue or where this pictures folder can