Example #1
0
/**
 * Send data to the floppy image I/O
 * 
 * @param data
 * @return 
 */
int FloppyIO::send(string strData) {
    // Prepare send buffer
    char * dataToSend = new char[this->szOutput];
    memset(dataToSend, 0, this->szOutput);
    
    // Initialize variables
    int szData = strData.length();
    int szPad = 0;
    
    // Copy the first szInput bytes
    if (szData > this->szOutput-1) {
        // Data more than the pad size? Trim...
        strData.copy(dataToSend, this->szOutput-1, 0);
    } else {
        // Else, copy the string to send buffer
        strData.copy(dataToSend, szData, 0);
    }
    
    // Write the data to file
    this->fIO->seekp(this->ofsOutput);
    this->fIO->write(dataToSend, this->szOutput);
    
    // Notify the client that we placed data (Client should clear this on read)
    this->fIO->seekp(this->ofsCtrlByteOut);
    this->fIO->write("\x01", 1);
    
}
Example #2
0
void split(string &str, string sep_char, string &str_bef, string &str_aft)
{
    // Separate the string into two at the specified separating character
    size_t found;
    size_t length;
    int loc;

    char buffer[5000];
    // I am assuming the user wont put an entry greater than 100 charaters long! 
    // (50 was kinda not enough -given long name of files)

    found=str.find(sep_char);
    if (found!=string::npos)
    {
        loc=int(found);
        
        length=str.copy(buffer,loc,0);
        buffer[length]='\0';
        str_bef=buffer;
        
        length=str.copy(buffer,str.size()-loc,loc+1);
        buffer[length]='\0';
        str_aft=buffer;
    }
}
Example #3
0
// Send data to the floppy image I/O
// @param data
// @return 
void FloppyIO::send(string strData) {
    CRASH_REPORT_BEGIN;

    // Make sure we are initialized
    if (this->fIO == NULL) return;

    // Prepare send buffer
    char * dataToSend = new char[this->szOutput];
    memset(dataToSend, 0, this->szOutput);
    
    // Initialize variables
    int szData = strData.length();
    
    // Copy the first szInput bytes
    if (szData > this->szOutput-1) {
        // Data more than the pad size? Trim...
        strData.copy(dataToSend, this->szOutput-1, 0);
    } else {
        // Else, copy the string to send buffer
        strData.copy(dataToSend, szData, 0);
    }
    
    // Write the data to file
    this->fIO->seekp(this->ofsOutput, ios_base::beg);
    this->fIO->write(dataToSend, this->szOutput);
    
    // Notify the client that we placed data (Client should clear this on read)
    this->fIO->seekp(this->ofsCtrlByteOut, ios_base::beg);
    this->fIO->write("\x01", 1);

    // Delete buffer
    delete[] dataToSend;
    CRASH_REPORT_END;
}
Example #4
0
bool decodeLI(string& sOpCode,string& sLine)
{
	// LI t.I, o // Integer load immediate

	bool isDouble = 0;
	int i;
	char reg[4],immediate[20];
	int *itarget;

	memset(&reg,'\0',4);
	if((i = sLine.find(",")) > 0)
	{
		sLine.copy(reg,i,0);
		reg[i] = '\0';
	}
	else
	{
		cout<<"Syntax Error. Line No. "<<programCounter+1<<endl;
		return E_FAIL;
	}
	if(!validateRegister(decodeExecute.isDouble,reg))
	{
		cout<<"Invalid register. Program Line No. "<<programCounter+1<<endl;
		return E_FAIL;
	}
	sLine.copy(cImmediate,sLine.length()-i,i+1);
	decodeExecute.targetRegister.assign(reg);
	decodeExecute.target = &integer_registers[reg];

	return E_SUCCESS;
}
	void splitFileRecord(string line, int recordNo)
	{
		cout<<"\n";
		size_t found;
		int len = line.size();
		int pos = 0;
		char buffer[20];
		size_t buf_size;
		vector <string> fileFields;
		fileFields.clear();

		do
		{
			found = splitByChar(line,'_',pos);

			if(found > len)
				break;
			else
			{			
				buf_size = line.copy(buffer,found - pos,pos);
				buffer[buf_size] = '\0';
				fileFields.push_back(buffer);
			}
			pos = found + 1;

		}while(found != string::npos);

		buf_size = line.copy(buffer,len - pos,pos);
		buffer[buf_size] = '\0';
		fileFields.push_back(buffer);

		fillFileRecord(fileFields, recordNo);
		
	}
Example #6
0
void ExtractInfo(string data, double & min, double & max, double & step, string & theinfo, bool & isrange, bool isstring) {

	size_t pos = data.find( '-' );
	if( pos != string::npos ) { // A range

		isrange = true;
		char temp[__max_length];
		char temp2[__max_length];

		// first number
		data.copy(temp, pos, 0);	// copy the interesting part
		// erase
		data.erase(0, pos+1);		// erase from string
		temp[pos+1] = '\0';			// terminate correctly
		min = atof( temp ); 		// atof

		// second number
		pos = data.find( ':' );
		data.copy(temp2, pos, 0);	// copy the interesting part
		// erase
		data.erase(0, pos+1);		// erase from string
		temp2[pos+1] = '\0';		// terminate correctly
		max = atof( temp2 ); 		// atof

		// step
		step = atof( data.c_str() ); 		// atof

	} else {
		if ( ! isstring ) min = atof( data.c_str() );
		else theinfo = data;
		isrange = false;
	}

}
Example #7
0
EthernetSocket::EthernetSocket(const string &p_interfaceName)
    : interfaceName ( p_interfaceName ), socket_address(), sendBuffer (BUFFER_SIZE), receiveBuffer (BUFFER_SIZE)
{
    if (p_interfaceName.length() > IFNAMSIZ) {
        // Throw exception
        throw invalid_argument("Interface name is too long.");
    }

    // Open RAW socket to send on
    if ((sockfd = socket(AF_PACKET, SOCK_RAW, htons(CUSTOM_ETH_TYPE))) == -1) {
        throw invalid_argument(strerror(errno));
    }

    // Get interface ID
    {
        // value-initialisation will perform zero-initialisation
        struct ifreq if_idx {};
        p_interfaceName.copy(if_idx.ifr_name, p_interfaceName.length());
        if (ioctl(sockfd, SIOCGIFINDEX, &if_idx) < 0) {
            close(sockfd);
            throw invalid_argument(string("SIOCGIFINDEX") + strerror(errno));
        }
        socket_address.sll_ifindex = if_idx.ifr_ifindex;
    }

    // Get interface MAC Address
    {
        // value-initialisation will perform zero-initialisation
        struct ifreq if_mac {};
        p_interfaceName.copy(if_mac.ifr_name, p_interfaceName.length());
        if (ioctl(sockfd, SIOCGIFHWADDR, &if_mac) < 0) {
            close(sockfd);
            throw invalid_argument(string("SIOCGIFHWADDR") + strerror(errno));
        }
        interfaceMac.setMacArray(*(uint8_t(*)[6])&if_mac.ifr_hwaddr.sa_data);
    }

    // Set interface to promiscuous mode - Without this, only broadcasts and packets directed to us are received ( and sent?)
    {
        struct ifreq if_opts {};
        p_interfaceName.copy(if_opts.ifr_name, p_interfaceName.length());
        if (ioctl(sockfd, SIOCGIFFLAGS, &if_opts) < 0) {
            close(sockfd);
            throw invalid_argument(string("SIOCGIFFLAGS") + strerror(errno));
        }
        // Add promiscuous mode to flags
        if_opts.ifr_flags |= IFF_PROMISC;
        if (ioctl(sockfd, SIOCSIFFLAGS, &if_opts) < 0) {
            close(sockfd);
            throw invalid_argument(string("SIOCSIFFLAGS") + strerror(errno));
        }
    }

    // Bind to device (For Reading)
    if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE, p_interfaceName.c_str(), IFNAMSIZ - 1) == -1)	{
        close(sockfd);
        throw invalid_argument(string("SO_BINDTODEVICE") + strerror(errno));
    }
}
Example #8
0
int main(){
	ios::sync_with_stdio(false);
	while(gets(s))
	{
		if(strcmp(s,"####")==0){
			map<pair<string,string>,int> :: iterator it;
			int mx=0;
			for(it=m.begin() ;it!=m.end() ;it++){
				//cout<<it->first.first<<' '<<it->first.second<<' '<<it->second<<endl;
				int num=it->second;
				if(num>mx){
					mx=num;
					ansa=it->first.first;
					ansb=it->first.second;
				}
			}
			ansa.copy(aa,ansa.length() ,0);*(aa+ansa.length())='\0';
			ansb.copy(bb,ansb.length() ,0);*(bb+ansb.length())='\0';
			printf("%s %s:%d\n",aa,bb,mx);
		//	cout<<ansa<<' '<<ansb<<":"<<mx<<endl;
			m.clear();
		}
		else{
			CLR(flag,0);
			//CLR(str,0);
			string a;
			int i=0,f=0,ff=0,len=strlen(s),tot=0;
			while(!islower(s[i]) && i<len) i++;
			while(i<len){
				while(islower(s[i])){
					f=1;a += s[i++];
				}
				if(f){
					str[tot++]=a;
					a.clear();
					f=0;
				}
				while(s[i]==' ') i++;
				while(s[i]==','||s[i]=='.') ff=1,i++;
				if(ff && islower(s[i])) {
					flag[tot-1]=1;
					ff=0;
				}
			}
			//REP(i,tot) cout<<flag[i]<<' ';cout<<endl;
			for(int i=0;i<tot-1;i++){
				if(!flag[i]) {
				//	cout<<str[i]<<' '<<str[i+1]<<endl;
					m[(make_pair(str[i],str[i+1]))]++;
				}
			}
		}
	}



	return  0;
}
Example #9
0
bool decodeMOVE(string& sOpCode,string& sLine)
{
	int i,icount=0;
	char reg[4];
	bool detecthazard(char *);

	while(icount < 2)
	{
		if((i = sLine.find(",")) > 0)
		{
			sLine.copy(reg,i,0);
			reg[i] = '\0';
		}
		else
		{
			sLine.copy(reg,sLine.length(),0);
			reg[sLine.length()] = '\0';
		}
		if(icount == 1 && (!validateRegister(decodeExecute.isDouble?0:1,reg)) ) 
		{
			cout<<"Invalid register. Program Line No. "<<programCounter+1<<endl;
			return E_FAIL;
		}
		else if(icount == 0 && (!validateRegister(decodeExecute.isDouble,reg)) )
		{
			cout<<"Invalid register. Program Line No. "<<programCounter+1<<endl;
			return E_FAIL;
		}
		if(icount == 1)	// store the target register
		{
			decodeExecute.targetRegister.assign(reg);
			if(decodeExecute.isDouble)
			{
				decodeExecute.target = &integer_registers[reg];
				cout<<"storing the target Integer register : "<<reg<<" Target Address : "<<decodeExecute.target<<endl;
			}
			else
			{
				decodeExecute.target = &float_registers[reg];
				cout<<"storing the target Float register : "<<reg<<" Target Address : "<<decodeExecute.target<<endl;
			}
		}
		else if(icount == 0)	// store the source 1 register
		{
			if(detecthazard(reg))
				return E_SUCCESS;

			if(decodeExecute.isDouble)
				sprintf(cTempA,"%f",float_registers[reg]);
			else
				sprintf(cTempA,"%d",integer_registers[reg]);
		}
		sLine.assign(sLine,i+1,sLine.length()-i-1);
		icount++;
	}
	return E_SUCCESS;
}
Example #10
0
void HFInterpreter::parse(const string& model, const string& object){
  //Copy model into local C-style string itsModel
  itsModel = new char[model.length()+1];
  model.copy(itsModel,string::npos);
  itsModel[model.length()]='\0';

  itsObject = new char[object.length()+1];
  object.copy(itsObject,string::npos);
  itsObject[object.length()]='\0';
  
	//Note: It's Library List is now Empty
  init();
}
Example #11
0
// Send data to the floppy image I/O
//
// @param strData   The string to send
// @return          The number of bytes sent if successful or -1 if an error occured.
//
int FloppyIO::send(string strData) {
    // Prepare send buffer
    char * dataToSend = new char[this->szOutput];
    memset(dataToSend, 0, this->szOutput);
    
    // Check for ready state
    if (!this->ready()) return this->setError(-4, "Stream is not ready!");

    // Initialize variables
    int szData = (int)strData.length();
    int bytesSent = szData;
    
    // Copy the first szInput bytes
    if (szData > this->szOutput-1) { // -1 for the null-termination
        // Data more than the pad size? Trim...
        strData.copy(dataToSend, this->szOutput-1, 0);
        bytesSent = this->szOutput-1;
    } else {
        // Else, copy the string to send buffer
        strData.copy(dataToSend, szData, 0);
    }
    
    // Check for stream status
    if (!this->fIO->good()) return this->setError(-1, "I/O Stream reported no-good state while sending!");
    
    // Write the data to file
    this->fIO->seekp(this->ofsOutput);
    this->fIO->write(dataToSend, this->szOutput);
    
    // Check if something went wrong after writing
    if (!this->fIO->good()) return this->setError(-1, "I/O Stream reported no-good state while sending!");
    
    // Notify the client that we placed data (Client should clear this on read)
    this->fIO->seekp(this->ofsCtrlByteOut);
    this->fIO->write("\x01", 1);
    this->fIO->flush();

    // If synchronized, wait for data to be written
    if (this->synchronized) {
        // Wait for input control byte to become 1
        int iState = this->waitForSync(this->ofsCtrlByteOut, 0, this->syncTimeout);
        if (iState<0) return iState;
    }

    // Return number of bytes sent
    return bytesSent;
    
}
void TestCommunicationChannel::SplitHelpExamples(string& buffer, 
								string& result, const string token)
{
	ACE_TRACE(ACE_TEXT("[TestCommunicationChannel::SplitHelpExamples()]"));
	
	string::size_type pos = 0;
	string replace_str("");
	char rm_buff[150];
	
	pos = buffer.find(token, pos);
	
	if (pos	== string::npos)
	{
		return;
	}
	
	++pos;
		
	int length = buffer.copy(rm_buff, pos, 0);
 	rm_buff[length] = '\0';
 	FindAndReplace(buffer, rm_buff, "");

	result = rm_buff;
	FindAndReplace(result, token, "");
	
	return;
}
Example #13
0
/*
fileOps class:
    create memory buffer for fileOps::bufferSize (8 * 512 byte segments)
    opens a file for read or write (not both!) (up to 32Gib)    */
fileOps::fileOps(string fname, bool Writing, short int bSize){
    // reset fserror:
    fserror = 0;
    cout << "  Object Constructor." << endl;
    // memory buffer size:
    bufferSize = bSize * 1024;
    cout << "  Buffer size: " << bufferSize << endl;
    // memory buffer:
    memBuffer = new char [bufferSize];
    // EOF position (maximum)
    endOffset = bufferSize;
    // set write mode on/off
    writeMode = Writing;
    // cast char array from string
    int i = fname.copy(filename, fname.size(), 0);
    filename[i]='\0';
    // current position:
    curPos = 0;
    // current segment of position
    curSeg = 0;
    // return and wait for write calls:
    if (writeMode == true){
        // Open file for write:
        os.open(filename, ios::binary);
        cout << "  Write mode selected" << endl;
    } else {
        cout << "  Read mode selected. Open file: " << filename << endl;
        is.open(filename, ios::binary);
        // Set fileSize as 0
        fileSize = 0;
        // read first chunk:
        fileOps::read();
        cout << "  Buffer written" << endl;
        }
    }
Example #14
0
double VFFile::getParameterIni(string paramname, string inifile){
    pos2 = inifile.find("=", inifile.find(paramname)) + 1; //Find start

    if(inifile.find(";", pos2) < inifile.find("\n", pos2))  //Find end
        pos1 = inifile.find(";", pos2) - 1;
    else
        pos1 = inifile.find("\n", pos2) - 1;

    while(!(isdigit(buf30[0] = inifile[pos2]) || buf30[0]=='.' || buf30[0]=='-') \
          && pos2<=pos1)
        pos2++;   //Find exact start - remove symbols

    inifile.copy(buf30, pos1 - pos2 + 1, pos2);

    buf0 = (int)(pos1 - pos2 + 1);
    buf30[buf0] = '\0';
    while(!isdigit(buf30[buf0-1])){ //Find exact end - remove symbols
        buf0--;
        buf30[buf0] = '\0';
    }

    buf01 = atof(buf30);

    return buf01;
}
Example #15
0
void food::setFoodName(const string &foodN){
    int len = foodN.size();
    len = ( len < 10 ? len : 9 );
    foodN.copy( foodName, len);
    foodName[len] = '\0';
//  foodName = name;
}
Example #16
0
void findMaxMin(string tetemp, int & max, int & min){//find the max and min
    int stringLength = tetemp.length();
    char charString[10];
    string stringA;
    tetemp.copy(charString, stringLength, 0);
    *(charString + stringLength)='\0';
    max = 11;
    min = -1;
    if(stringLength ==2){//set the max and min is same when it only one charater between[]
        if(isdigit(tetemp[1])){
            stringA = charString[1];
            max=min=atoi(stringA.c_str());
        }
    }else{//get the max and min when it more than one charater  between []
        if(isdigit(tetemp[1])){//get the min
            stringA= charString[1];
            min=atoi(stringA.c_str());
            if(isdigit(tetemp[2])){
                stringA= charString[1]; 
                int a= min*10;
                min=atoi(stringA.c_str())+a;                
            }
        }
        if(isdigit(tetemp[stringLength-1])){//get the max
            stringA = charString[stringLength-1];
            max = atoi(stringA.c_str());
            if(isdigit(tetemp[stringLength-2])){
                stringA= charString[stringLength-2];
                int a= atoi(stringA.c_str());
                max= a*10 +max;                
            }
        }
        
    }
}
Example #17
0
void run(string cmd, string data, string token) {
	if (cmd == "reverse") {
		reverse(data.begin(), data.end());
		cout << data << endl;
	}

	else if (cmd == "split") {
		size_t len = data.length();
		char cstr[len], *result;
		data.copy(cstr, len);
		cstr[len] = '\0';
		result = strtok(cstr, token.c_str());
		while (result) {
			cout << result << " ";
			result = strtok(NULL, token.c_str());
		}
		cout << endl;
	}

	else if (cmd == "exit")
		exit(0);

	else
		cout << "error: invalid command" << endl;
}
Example #18
0
// Returns true if str1[] is a subsequence of str2[]. m is
// length of str1 and n is length of str2
bool isSubSequence(string str1, string str2)
{
	int j = 0; // For index of str1 (or subsequence

	// Traverse str2 and str1, and compare current character 
	// of str2 with first unmatched char of str1, if matched 
	// then move ahead in str1
	int n = str1.size();
	int m = str2.size();
       	int length = str2.copy(sorted_str,m,0);
	sorted_str[length] = '\0';
	//cout << "SORTED STR " << sorted_str << endl;
	//cout << "LENGTH " << length << endl;
	string sorted_string(sorted_str);
	sort(sorted_string.begin(),sorted_string.end());
	//cout << "sorted string " << sorted_string << endl;
	// cout << "str1 " << str1 << endl;
	//cout << "str2 " << str2 << endl;
	for (int i=0; i<m && j<n ; i++){
		if ( !binary_search(sorted_string.begin(),sorted_string.end(),str1[j]) )
		{
		//	cout << "Not Found! " << endl;
			return false;
		}
		if (str1[j] == str2[i]){
			j++;
		}
	}

	// If all characters of str1 were found in str2
	//cout << "j " << j << endl;
	//cout << "n " << n << endl;
	return (j==n);
}
vector<string> astrolabe::util::split(const string &str) {
    /* Split the whitespace-separated fields of a string.
    
    Parameters:
        str : a string
        
    Returns:
        a vector<> of strings
    
    */
    vector<string> results;
#ifdef _MSC_VER
	char cstr[1000];
#else
    char cstr[str.length() + 1];
#endif
    str.copy(cstr, string::npos);
    cstr[str.length()] = 0;
    const char delim[] = " \t\n";
    char *p = strtok(cstr, delim);
    while(p) {
        results.push_back(p);
        p = strtok(NULL, delim);
        }
    return results;
    }
Example #20
0
void constructMessage(Job& _msg, int _id, string _instrn) {
	_msg.jobid = _id;
	_instrn.copy(_msg.instrn,_instrn.size());
	_msg.instrn[_instrn.size() + 1] = '\0';
	//cout << _msg.instrn << endl;

}
 void reverseWords(string &s) {
     vector<string> sv;
     size_t i = 0, size = s.size(), offset = 0, len = 0;
     char tmp[MAX];
     while (true) {
         if (i==size)
             break;
         if (isspace(s[i])) {
             i++;
             continue;
         }
         offset = i; len = 0;
         while (i!=size && !isspace(s[i])) {
             len++; i++;
         }
         s.copy(tmp, len, offset);
         tmp[len] = '\0';
         sv.push_back(tmp);
     }
     s = "";
     if (sv.size()==0)
         return;
     vector<string>::size_type index=sv.size()-1;
     while (index!=0)
         s = s + sv[index--] + " ";
     s = s + sv[index];
 }
Example #22
0
 // set last-name value
 void ClientData::setUserName( string UserNameString )
{
 // copy at most 15 characters from string to lastName
int length = UserNameString.size();
 length = ( length < 15 ? length : 14 );
 UserNameString.copy(UserName, length);
 UserName[ length ] = '\0' ; // append null character to lastName
 } // end function setName
Example #23
0
void Hardware::setHardwareName( string HardwareNameString )
{
   int length = HardwareNameString.size();
   length = ( length < LENGTH ? length : LENGTH - 1 );
   HardwareNameString.copy( HardwareName, length );

   HardwareName[ length ] = '\0';
}
// Make a lowercase copy of s:
string lowerCase(string& s) {
  char* buf = new char[s.length()];
  s.copy(buf, s.length());
  for(int i = 0; i < s.length(); i++)
    buf[i] = tolower(buf[i]);
  string r(buf, s.length());
  delete buf;
  return r;
}
Example #25
0
void StringTest::copy()
{
    string s("foo");
    char dest[4];
    dest[0] = dest[1] = dest[2] = dest[3] = 1;
    CPPUNIT_ASSERT(s.copy(dest, 4) == 3);
    int pos = 0;
    CPPUNIT_ASSERT( dest[pos++] == 'f' );
    CPPUNIT_ASSERT( dest[pos++] == 'o' );
    CPPUNIT_ASSERT( dest[pos++] == 'o' );
    CPPUNIT_ASSERT( dest[pos++] == 1 );

    dest[0] = dest[1] = dest[2] = dest[3] = 1;
    CPPUNIT_ASSERT(s.copy(dest, 4, 2) == 1);
    pos = 0;
    CPPUNIT_ASSERT( dest[pos++] == 'o' );
    CPPUNIT_ASSERT( dest[pos++] == 1 );
}
Example #26
0
void
SmiKey::SetKey( const string& key )
{
  FreeData();
  keyType = SmiKey::String;
  keyLength  = (key.length() <= SMI_MAX_KEYLEN) ? key.length() : SMI_MAX_KEYLEN;
  if ( keyLength > SMI_MAX_KEYLEN_LOCAL )
  {
    longKeyData = new char[keyLength+1];
    key.copy( (char*) longKeyData, keyLength );
    longKeyData[keyLength] = 0;
  }
  else
  {
    key.copy( shortKeyData, keyLength );
    shortKeyData[keyLength] = 0;
  }
}
// set tool-name value
void Tool::setToolName( string toolNameString )
{
   // copy at most 30 characters from string to toolName
   int length = toolNameString.size();
   length = ( length < LENGTH ? length : LENGTH - 1 );
   toolNameString.copy( toolName, length );

   // append null-terminating character to end of toolName
   toolName[ length ] = '\0';
} // end function setToolName
Example #28
0
	virtual int
	pullData(void *buf, unsigned int size) {
		int result;

		lock();

		switch (status) {
		case HTTP_READER_ERROR:
			result = -2;
			break;
		case HTTP_READER_DONE:
			if (downloadBuffer.empty()) {
				result = 0;
			} else {
				result = (downloadBuffer.size() > size) ?
					size :
					downloadBuffer.size();
				downloadBuffer.copy(reinterpret_cast<char *>(buf), result);
				downloadBuffer.erase(0, result);
			}
			break;
		case HTTP_READER_DOWNLOADING:
			if (downloadBuffer.empty()) {
				result = -1;
			} else {
				result = (downloadBuffer.size() > size) ?
					size :
					downloadBuffer.size();
				downloadBuffer.copy(reinterpret_cast<char *>(buf), result);
				downloadBuffer.erase(0, result);
			}
			break;
		default:
			result = -2;
			fprintf(stderr, "StdHttpReader: invalid status %d\n", status);
			abort();
			break;
		};

		unlock();

		return result;
	}
Example #29
0
int main (void)
{
#ifndef ONLINE_JUDGE
    freopen ("T1008.in", "r", stdin);
    freopen ("T1008.out", "w", stdout);
#endif

    getline (cin, line);
    bool first=true;
    int sep;
    for (int i=0; i<line.size(); ++i)
    {
        if (line[i]==' ')
        {
            first=false;
            sep=i;
            break;
        }
    }

    if (first)
    {
        char N[10];
        line.copy(N, line.size());
        n=atol(N);
        One();
    }

    else
    {
        char N[10];
        draw.resize(1);
        line.copy(N, sep);
        draw[0].x=atol(N);
        line.copy(N, line.size()-sep, sep+1);
        draw[0].y=atol(N);
        q.push(0);
        Second();
    }

    return 0;
}
void Customer::setCustomerName( const string &customerNameString )
{
   int length = customerNameString.size();
   length = ( length < 20 ? length : 19 );
   string str = customerNameString;
   char *cstr = new char[str.length() + 1];
	strcpy(cstr, str.c_str());
   customerNameString.copy( cstr, length );
   customerName[ length ] = '\0';
   customerName = customerNameString;
}