CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2013
    Posts
    1

    my build .exe files stopped

    My code was running good and passed the compiler.
    However, when I tried to run the .exe files from the release, it shows xxxxx.exe files stopped.
    I think the problem is in the open the .ini files and read them put them into string array because that it doesn't have any problem before I add those function.

    Please help and give me some advice.
    Thank you

    Code:
    #include "stdafx.h"
    #include "MySignalHound.h"
    #include "math.h"
    #include "windows.h"
    #include <iostream>
    #include <fstream>
    #include "windows.h"
    #include <sstream>
    #include <string>
    
    using namespace std;
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	CMySignalHound myHound;
    	//int centerFreq;
    	//int span;
    	//int chSp;
    	//int rbwPt;
    
    	int ini = myHound.Initialize();
    		if(ini!=0)
    		{			
    
    			MessageBox(NULL,L"USB Connection Error",L"Connection Error!!!", MB_OK|MB_ICONINFORMATION);
    		 //	cout<< ini;
    		//	system("pause");
    		//	exit(1);	
    
    		}
    		else{
    								
    			ifstream setup;
    			setup.open("setup.ini");
    			
    			if(!setup){
    				MessageBox(NULL,L"Can't open setup files",L"Error", MB_OK|MB_ICONINFORMATION);
    			
    			}
    			else
    			{
    				string input[8];
    				int i = 0;
    				while(!setup.eof())
    				{
    					
    					getline(setup,input[i]);
    				//	cout<<input[i]<<endl;
    					i++;				
    				}
    				setup.close();
    				
    				int centerFreq;
    				int span;
    				int chSp;
    				int rbwPt;
    				
    				stringstream(input[1]) >> centerFreq;
    				stringstream(input[3]) >> span;
    				stringstream(input[5]) >> chSp;
    				stringstream(input[7]) >> rbwPt;
    				centerFreq = centerFreq*10e6;
    				span = span*10e6;
    				rbwPt = rbwPt*10e3;
    				chSp = chSp*10e3;
    			myHound.m_settings.m_RBWIsAuto = true;
    			myHound.m_settings.m_VBWIsAuto = true;
    			myHound.m_settings.m_RBWSetpoint = rbwPt;
    			//myHound.SetStartAndStop(175000000, 185000000);
    			myHound.SetCenterAndSpan(centerFreq,span);
    			//myHound.m_channelBW = 10000;
    			myHound.m_channelSpacing = chSp;
    			
    			int isSetup = myHound.SetupForSweep();
    			int isDoSweep= myHound.DoSweep();
    			int myTraceSize = myHound.m_traceSize;			
    			double myHzPerPoint = myHound.m_HzPerPt;
    			int peakidx=0; 
    		
    			
    	//Find Peak Idex
    					for(int i =1; i<myTraceSize;i++)
    					{	
    						if(myHound.pDataMax[i]>myHound.pDataMax[peakidx])
    						peakidx=i;
    					}
    		
    			double peakAmpl = mW2dBm(myHound.pDataMax[peakidx]);
    			double peakFreq = myHound.GetFrequencyFromIdx(peakidx)/10e6;
    			
    			if(peakAmpl<=-50 || peakFreq <=179 || peakFreq>=181)
    				{
    					
    					//errorCount++;
    					std::ofstream log("logfile.csv", std::ios_base::app | std::ios_base::out);
    					log <<peakAmpl<<" dBm"<< "," <<peakFreq <<" MHz "<<","<<"Error: "<<","<<"******"<<"\n" ;	
    					printf("Peak Amplitude: %.2f dBm    Peak Freq: %.2f MHz \n",peakAmpl,peakFreq);
    				}
    			else
    				{			
    					std::ofstream log("logfile.csv", std::ios_base::app | std::ios_base::out);
    					log <<peakAmpl<<" dBm"<< "," <<peakFreq <<" MHz "<<"\n" ;	
    					printf("Peak Amplitude: %.2f dBm    Peak Freq: %.2f MHz \n",peakAmpl,peakFreq);
    				}
    			
    			}
    	system("pause");
    	return 0;
    }
    }

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: my build .exe files stopped

    Quote Originally Posted by dtu0520 View Post
    My code was running good and passed the compiler.
    However, when I tried to run the .exe files from the release, it shows xxxxx.exe files stopped.
    I think the problem is in the open the .ini files and read them put them into string array because that it doesn't have any problem before I add those function.
    Instead of "thinking" you have to debug your code step-by-step to see what, where and how goes wrong or not as expected!
    Victor Nijegorodov

  3. #3
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,721

    Re: my build .exe files stopped

    As Victor mentioned, debugging yoiur code would lead to the answer quickly.

    Some notes:

    1) checking eof() in the loop as you coded it, leads to the loop body
    being accessed one more time than it should. An alternative loop:
    Code:
    int i = 0;
    while( i<8 && getline(setup,input[i]))
    {		
       i++;				
    }
    2) Anothe way is to make input a vector instead of an array.
    If the number of lines in the ini file change, you will not need
    to change the reading section:

    Code:
    string line;
    vector<string> input;
    
    while(getline(setup,line))
    {		
       input.push_back(line);
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured