<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Zeichen ersetzten gibt Errors zurück]]></title><description><![CDATA[<p>Hallo Zusammen ich hab folgende Funktion: (ersetzt mir \x0a und \x0d durch Leerzeichen).</p>
<pre><code class="language-cpp">void replace(char** buffer, char search, char replacement)
{
	if(buffer == NULL || *buffer == NULL) return;
	char* str = *buffer;
	while(*str++ != '\0')
	{
		if(*str == search) *str = replacement;
	}
}
</code></pre>
<p>Wenn ich die Funktion in einem Programm so aufrufe funktioniert es Perfekt:</p>
<pre><code class="language-cpp">int main(int argc, const char** argv) {
  char* test = (char*) malloc(sizeof(char) * 13);
  strncpy(test, &quot;Servus\x0a\x0dtest\0&quot;, 13); // 53 65 72 76 75 73 0a 0d 74 65 73 74 00

  replace(&amp;test, '\x0a', ' ');
  replace(&amp;test, '\x0d', ' ');
  puts(test);  // 53 65 72 76 75 73 20 20 74 65 73 74 00

  return 0;
}
</code></pre>
<p>Jedoch wenn ich die Funktion in Mein Programm einbinden will geht gar niichts mehr:</p>
<pre><code class="language-cpp">char *rxBuffer // Wert wurde schon früher zugewiesen

  replace(&amp;rxBuffer, '\x0a', ' ');
  replace(&amp;rxBuffer, '\x0d', ' ');
  puts(rxBuffer);  // 53 65 72 76 75 73 20 20 74 65 73 74 00
</code></pre>
<p>Folgende Fehlermeldungen erscheinen:</p>
<p>--------------------Configuration: Fluke_45_Reader - Win32 Debug--------------------<br />
Compiling...<br />
CSerialPort.cpp<br />
Linking...<br />
CSerialPort.obj : error LNK2001: unresolved external symbol &quot;public: void __thiscall CSerialPort::replace(char * *,char,char)&quot; (?replace@CSerialPort@@QAEXPAPADDD@Z)<br />
Debug/Fluke_45_Reader.exe : fatal error LNK1120: 1 unresolved externals<br />
Error executing link.exe.<br />
Creating browse info file...</p>
<p>Fluke_45_Reader.exe - 2 error(s), 0 warning(s)</p>
<p>Ich hoffe ihr könnt mir helfen, bin schon den ganzen Morgen am gleichen Problem. Weis echt nicht mehr weiter.</p>
<p>Danke</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/276843/zeichen-ersetzten-gibt-errors-zurück</link><generator>RSS for Node</generator><lastBuildDate>Wed, 26 Aug 2026 05:29:38 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/276843.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 09 Nov 2010 09:58:32 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Zeichen ersetzten gibt Errors zurück on Tue, 09 Nov 2010 09:58:32 GMT]]></title><description><![CDATA[<p>Hallo Zusammen ich hab folgende Funktion: (ersetzt mir \x0a und \x0d durch Leerzeichen).</p>
<pre><code class="language-cpp">void replace(char** buffer, char search, char replacement)
{
	if(buffer == NULL || *buffer == NULL) return;
	char* str = *buffer;
	while(*str++ != '\0')
	{
		if(*str == search) *str = replacement;
	}
}
</code></pre>
<p>Wenn ich die Funktion in einem Programm so aufrufe funktioniert es Perfekt:</p>
<pre><code class="language-cpp">int main(int argc, const char** argv) {
  char* test = (char*) malloc(sizeof(char) * 13);
  strncpy(test, &quot;Servus\x0a\x0dtest\0&quot;, 13); // 53 65 72 76 75 73 0a 0d 74 65 73 74 00

  replace(&amp;test, '\x0a', ' ');
  replace(&amp;test, '\x0d', ' ');
  puts(test);  // 53 65 72 76 75 73 20 20 74 65 73 74 00

  return 0;
}
</code></pre>
<p>Jedoch wenn ich die Funktion in Mein Programm einbinden will geht gar niichts mehr:</p>
<pre><code class="language-cpp">char *rxBuffer // Wert wurde schon früher zugewiesen

  replace(&amp;rxBuffer, '\x0a', ' ');
  replace(&amp;rxBuffer, '\x0d', ' ');
  puts(rxBuffer);  // 53 65 72 76 75 73 20 20 74 65 73 74 00
</code></pre>
<p>Folgende Fehlermeldungen erscheinen:</p>
<p>--------------------Configuration: Fluke_45_Reader - Win32 Debug--------------------<br />
Compiling...<br />
CSerialPort.cpp<br />
Linking...<br />
CSerialPort.obj : error LNK2001: unresolved external symbol &quot;public: void __thiscall CSerialPort::replace(char * *,char,char)&quot; (?replace@CSerialPort@@QAEXPAPADDD@Z)<br />
Debug/Fluke_45_Reader.exe : fatal error LNK1120: 1 unresolved externals<br />
Error executing link.exe.<br />
Creating browse info file...</p>
<p>Fluke_45_Reader.exe - 2 error(s), 0 warning(s)</p>
<p>Ich hoffe ihr könnt mir helfen, bin schon den ganzen Morgen am gleichen Problem. Weis echt nicht mehr weiter.</p>
<p>Danke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1977671</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1977671</guid><dc:creator><![CDATA[TTS]]></dc:creator><pubDate>Tue, 09 Nov 2010 09:58:32 GMT</pubDate></item><item><title><![CDATA[Reply to Zeichen ersetzten gibt Errors zurück on Tue, 09 Nov 2010 10:08:05 GMT]]></title><description><![CDATA[<p>[Murks]</p>
<p>Hast du die .cpp in´s Projekt aufgenommen?<br />
Ist sie jetzt vielleicht member der Klasse CSerialPort?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1977675</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1977675</guid><dc:creator><![CDATA[DocShoe]]></dc:creator><pubDate>Tue, 09 Nov 2010 10:08:05 GMT</pubDate></item><item><title><![CDATA[Reply to Zeichen ersetzten gibt Errors zurück on Tue, 09 Nov 2010 10:12:03 GMT]]></title><description><![CDATA[<p>DocShoe schrieb:</p>
<blockquote>
<p>[Murks]</p>
<p>Hast du die .cpp in´s Projekt aufgenommen?<br />
Ist sie jetzt vielleicht member der Klasse CSerialPort?</p>
</blockquote>
<p>Ja die .cpp habe ich ins Projekt aufgenommen, dieses File existiert schon länger</p>
<p>Ja, die Funktion replace ist member der Klasse CSerialPort.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1977679</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1977679</guid><dc:creator><![CDATA[TTS]]></dc:creator><pubDate>Tue, 09 Nov 2010 10:12:03 GMT</pubDate></item><item><title><![CDATA[Reply to Zeichen ersetzten gibt Errors zurück on Tue, 09 Nov 2010 10:13:32 GMT]]></title><description><![CDATA[<p>Dann poste doch mal bitte die .h und .cpp Datei.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1977681</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1977681</guid><dc:creator><![CDATA[DocShoe]]></dc:creator><pubDate>Tue, 09 Nov 2010 10:13:32 GMT</pubDate></item><item><title><![CDATA[Reply to Zeichen ersetzten gibt Errors zurück on Tue, 09 Nov 2010 10:16:39 GMT]]></title><description><![CDATA[<p>CSerialPort.h</p>
<pre><code class="language-cpp">// CSerialPort.cpp : Defines the entry point for the console application.
//
#include &lt;windows.h&gt;
#include &lt;AFX.h&gt;
#include &lt;stdio.h&gt;
#include &lt;time.h&gt;
#include &lt;iostream&gt;
using std::cin;
#include &lt;fstream&gt;
#include &lt;assert.h&gt;
#include &lt;string&gt;
#include &lt;direct.h&gt;

using namespace std;

//defs
#define BUFFER_SIZE							255
#define FLUKE45_START_CHAR					0x68
#define FLUKE45_END_CHAR					0x16
#define DEFAULT_BAUDRATE					9600

#ifndef __FLUKE45_H__
#define __FLUKE45_H__

class CSerialPort
{
public:

	/*
	 * Constructor
	 */
	CSerialPort (BOOL debugEnabled):
	  hComm(INVALID_HANDLE_VALUE)
		{};

	/*
	 * Deconstructor
	 */
	~CSerialPort ();

	/*
	 * Open() opens the COM port and configures it with the specified parameters.
	 *
	 * @param [in] comPortNumber: number of COM port
	 * @param [in] baudRate     : baud rate [bit/s]
	 * @return     TRUE, if COM port has been successfully opened and configured
	 *             FALSE, otherwise
	 */
	BOOL Open (int comPortNumber, int baudRate);

	/*
	 * Close() closes the COM port
	 *
	 * @return TRUE, if COM port has been closed successfully
	 *         FALSE, otherwise
	 */
	BOOL Close (void);

    /*
	 * ReceiveData() receives receives bytes from COM port and writes them to receiveBuffer.
	 * The function returns if bytesToReceive bytes have been received or a timeout occured.
	 *
	 * @param [in]  bytesToReceive: number of bytes which are received before the function returns
	 * @param [out] rxBuffer      : buffer where the received bytes are written to
	 * @param [out] bytesReceived : number of bytes which have been received
	 * @return      TRUE, if bytesToReceive bytes have been received
	 *              FALSE, otherwise
	 */
	BOOL ReceiveData(int bytesToReceive, char* rxBuffer, unsigned long* bytesReceived);

	/*
	 * SendData() sends bytes from the txBuffer to the COM port
	 * The function returns if all bytes have been sent or an error occured
	 *
	 * @param [in]  bytesToSend: number of bytes which are sent before the function returns
	 * @param [in]  txBuffer   : buffer, where the bytes to send are stored
	 * @param [out] bytesSent  : number of bytes, wich have been sent
	 * @return		TRUE,  if bytesToSend have been sent
	 *				FALSE, otherwise
	 */
	BOOL SendData(int bytesToSend, char* txBuffer, unsigned long* bytesSent);

	/*
	 * SetDebugMode() if IsEnabled is true the function activates the debug mode
	 * 
	 * @param [in]  IsEnabled	  : If the Debug Mode is enabled over the arguments IsEnabled = true
	 * @param [in]  recDataArray  : Buffer, where the messages from the Fluke are stored.
	 * @param [in]	MessageToFluke: Buffer, where the messages to the Fluke are stored.
	 * @param [in]	timeStamp	  : Variable, where the timeStamp is stored.
	 *				
	 */
    void SetDebugMode(BOOL debugEnabled);

	void replace(char** buffer, char search, char replacement);

private:
	HANDLE  hComm;

	BOOL m_isDebugModeEnabled;
};

#endif
</code></pre>
<p>CSerialPort.cpp</p>
<pre><code class="language-cpp">#include &quot;CSerialPort.h&quot;
#include &quot;DateTime.h&quot;
#include &quot;windows.h&quot;
#include &lt;afx.h&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;
#include &lt;string.h&gt;

//-----------------------------------------------------------------------------
CSerialPort::~CSerialPort()
{
	Close ();
}

//-----------------------------------------------------------------------------
BOOL CSerialPort::Open(int comPortNumber, int baudRate)
{
	char szPort[16];
	DCB dcb;
	COMMTIMEOUTS timeouts;

	if (hComm != INVALID_HANDLE_VALUE)
	{
		return (TRUE);
	}

    // open COM port
	wsprintf (szPort, &quot;\\\\.\\COM%d&quot;, comPortNumber);
	hComm = CreateFile (szPort,
						GENERIC_READ | GENERIC_WRITE,
						FILE_SHARE_READ | FILE_SHARE_WRITE,
						0,
						OPEN_EXISTING,
						FILE_ATTRIBUTE_NORMAL,
						NULL);
	if (hComm == INVALID_HANDLE_VALUE)
		return (FALSE);

	// set timeout
	if (!GetCommTimeouts(hComm, &amp;timeouts))
	{
		Close ();
		return (FALSE);
	}
	timeouts.ReadIntervalTimeout         = 0 ;   // Specifies the maximum time, allowed to elapse between the arrival of two characters on the communications line. 
	timeouts.ReadTotalTimeoutMultiplier  = 1 ;   // For each read operation, this value is multiplied by the requested number of bytes to be read. used to calculate the total time-out period for read operations.
	timeouts.ReadTotalTimeoutConstant    = 3000; // For each read operation, this value is added to the product of the ReadTotalTimeoutMultiplier member and the requested number of bytes. 
	timeouts.WriteTotalTimeoutMultiplier = 1000; // For each write operation, this value is multiplied by the number of bytes to be written. used to calculate the total time-out period for write operations.
	timeouts.WriteTotalTimeoutConstant   = 1000; // For each write operation, this value is added to the product of the WriteTotalTimeoutMultiplier member and the number of bytes to be written. Used to calculate the total time-out period for write operations. 
	if (!SetCommTimeouts(hComm, &amp;timeouts))
	{
		Close ();
		return (FALSE);
	}

    // configure COM port	
	ZeroMemory (&amp;dcb, sizeof(dcb));
	if (!GetCommState (hComm, &amp;dcb))
	{
		Close ();
		return (FALSE);
	}

	dcb.BaudRate     = baudRate;		// baud rate 
	dcb.fBinary      = TRUE;			// must be true
	dcb.fParity      = FALSE;			// no parity bit
	dcb.fOutxCtsFlow = FALSE;			// monitor clear to send
	dcb.ByteSize     = (byte)8;         // number of bits
	dcb.StopBits = ONESTOPBIT;			// one stop bit

	if (!SetCommState(hComm, &amp;dcb))
	{
		Close ();
		return (FALSE);
	}

	return(TRUE);
}

//-----------------------------------------------------------------------------
BOOL CSerialPort::Close (void)
{
	BOOL bResult;

	if(hComm == INVALID_HANDLE_VALUE)
	{
		return (TRUE);
	}

	// close COM port
	bResult = CloseHandle(hComm);
	hComm   = INVALID_HANDLE_VALUE;

	return(bResult);
}

//-----------------------------------------------------------------------------
BOOL CSerialPort::SendData (int bytesToSend, char* txBuffer, unsigned long* bytesSent)
{ 
	BOOL sendState;

	if (hComm == INVALID_HANDLE_VALUE)
	{
		return (FALSE);
	}

	sendState = WriteFile(hComm, txBuffer, bytesToSend, bytesSent, NULL);

	if (m_isDebugModeEnabled == 1)
	{
		cout&lt;&lt; &quot;    &quot;&lt;&lt; &quot;Pc --&gt; Fluke : &quot; &lt;&lt; txBuffer &lt;&lt; endl;
	}
	 /*&lt;&lt;timeStamp */ 
	return (sendState);
}

//-----------------------------------------------------------------------------
BOOL CSerialPort::ReceiveData (int bytesToReceive, char *rxBuffer, unsigned long* bytesReceived)
{
	BOOL readState;

	if (hComm == INVALID_HANDLE_VALUE)
	{
		return (FALSE);
	}

	readState = ReadFile(hComm,rxBuffer , bytesToReceive, bytesReceived, NULL);

	if (m_isDebugModeEnabled == 1)
	{
		  replace(&amp;rxBuffer, '\x0a', ' ');
		  replace(&amp;rxBuffer, '\x0d', ' ');
		  puts(rxBuffer);  // 53 65 72 76 75 73 20 20 74 65 73 74 00 
	}

		cout &lt;&lt;&quot;   &quot; &lt;&lt; &quot;Fluke --&gt; PC : &quot;  &lt;&lt; endl;

	/*&lt;&lt;timeStamp */
	return (readState);
}

//-----------------------------------------------------------------------------
void CSerialPort::SetDebugMode(BOOL debugEnabled)
{
	m_isDebugModeEnabled = debugEnabled;
}

//-----------------------------------------------------------------------------
void replace(char** buffer, char search, char replacement)
{
	if(buffer == NULL || *buffer == NULL) return;
	char* str = *buffer;
	while(*str++ != '\0')
	{
		if(*str == search) *str = replacement;
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1977682</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1977682</guid><dc:creator><![CDATA[TTS]]></dc:creator><pubDate>Tue, 09 Nov 2010 10:16:39 GMT</pubDate></item><item><title><![CDATA[Reply to Zeichen ersetzten gibt Errors zurück on Tue, 09 Nov 2010 10:28:45 GMT]]></title><description><![CDATA[<p>Danke für die Hilfe, hat sich erledigt.</p>
<p>im CPP File, wo die Funktion implementiert wurde habe ich vergessen zu schreiben &quot;CSerialPort::replace&quot;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1977690</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1977690</guid><dc:creator><![CDATA[TTS]]></dc:creator><pubDate>Tue, 09 Nov 2010 10:28:45 GMT</pubDate></item></channel></rss>