473,738 Members | 3,854 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

strcat - strange behavior

I'm working on a simple piece of code under VC++ 6.0. I've got a char
Buffer array into which I copy the contents of an MFC control. The
string is properly nul terminated. I use strcat (Buffer, "\r\n") to
append a carriage return\line feed to the string before outputting it
to a display where I can monitor what's being exchanged with another
service. But after the strcat the string in Buffer is terminated, not
with \r\n but with a \n and NO nul terminator. The carriage return is
dropped completely.

If this was output for a text file I'd think it was an expected
conversion. But all of this is still in memory.

TIA,
Lilith
Feb 27 '06 #1
16 5164
Lilith wrote:
I'm working on a simple piece of code under VC++ 6.0. I've got a char
Buffer array into which I copy the contents of an MFC control.
You know that MFC is off-topic, right? Just checking. I understand that
you're not asking about MFC per se.
The
string is properly nul terminated. I use strcat (Buffer, "\r\n") to
append a carriage return\line feed to the string before outputting it
to a display
Outputting a string to a display is not defined in C++, you know that,
right? There is no such thing as "display" in C++.
where I can monitor what's being exchanged with another
service. But after the strcat the string in Buffer is terminated, not
with \r\n but with a \n and NO nul terminator.
I think this is covered in the FAQ. See 5.8.
The carriage return is
dropped completely.

If this was output for a text file I'd think it was an expected
conversion. But all of this is still in memory.


I'll believe you when I see the code.

V
--
Please remove capital As from my address when replying by mail
Feb 27 '06 #2
On Mon, 27 Feb 2006 17:08:53 -0500, Victor Bazarov
<v.********@com Acast.net> wrote:
Lilith wrote:
I'm working on a simple piece of code under VC++ 6.0. I've got a char
Buffer array into which I copy the contents of an MFC control.
You know that MFC is off-topic, right? Just checking. I understand that
you're not asking about MFC per se.
Even when I'm striving for completeness?
The
string is properly nul terminated. I use strcat (Buffer, "\r\n") to
append a carriage return\line feed to the string before outputting it
to a display Outputting a string to a display is not defined in C++, you know that,
right? There is no such thing as "display" in C++.
Yes, and once again, the purpose was completeness. I wanted it
understood why I was appending the CR\LF combination.
where I can monitor what's being exchanged with another
service. But after the strcat the string in Buffer is terminated, not
with \r\n but with a \n and NO nul terminator. I think this is covered in the FAQ. See 5.8. The carriage return is
dropped completely. If this was output for a text file I'd think it was an expected
conversion. But all of this is still in memory.

I'll believe you when I see the code.
strcpy (Buffer, "MAIL FROM: ");
m_From.GetWindo wText(Text, 512); // sorry if this is MFC
strcat (Buffer, Text); // up to this point the string is nul
// terminated

// Buffer is passed to a function but is still null
// terminated following the call

strcat(Buffer, "\r\n"); // after this operation the
// string is LF terminated with no
// nul
V


--
Lilith
Feb 27 '06 #3

Lilith wrote:
On Mon, 27 Feb 2006 17:08:53 -0500, Victor Bazarov
<v.********@com Acast.net> wrote:
Lilith wrote:
I'm working on a simple piece of code under VC++ 6.0. I've got a char
Buffer array into which I copy the contents of an MFC control.
You know that MFC is off-topic, right? Just checking. I understand that
you're not asking about MFC per se.


Even when I'm striving for completeness?
The
string is properly nul terminated. I use strcat (Buffer, "\r\n") to
append a carriage return\line feed to the string before outputting it
to a display
Outputting a string to a display is not defined in C++, you know that,
right? There is no such thing as "display" in C++.


Yes, and once again, the purpose was completeness. I wanted it
understood why I was appending the CR\LF combination.
where I can monitor what's being exchanged with another
service. But after the strcat the string in Buffer is terminated, not
with \r\n but with a \n and NO nul terminator.
I think this is covered in the FAQ. See 5.8.

The carriage return is
dropped completely. If this was output for a text file I'd think it was an expected
conversion. But all of this is still in memory.

I'll believe you when I see the code.


strcpy (Buffer, "MAIL FROM: ");
m_From.GetWindo wText(Text, 512); // sorry if this is MFC
strcat (Buffer, Text); // up to this point the string is nul
// terminated

// Buffer is passed to a function but is still null
// terminated following the call

strcat(Buffer, "\r\n"); // after this operation the
// string is LF terminated with no
// nul


What is strlen(Buffer) vs. sizeof(Buffer)?

Feb 27 '06 #4
On 27 Feb 2006 14:43:18 -0800, ro**********@gm ail.com wrote:

Lilith wrote:
On Mon, 27 Feb 2006 17:08:53 -0500, Victor Bazarov
<v.********@com Acast.net> wrote:
>Lilith wrote:
>> I'm working on a simple piece of code under VC++ 6.0. I've got a char
>> Buffer array into which I copy the contents of an MFC control.

>You know that MFC is off-topic, right? Just checking. I understand that
>you're not asking about MFC per se.


Even when I'm striving for completeness?
> > The
>> string is properly nul terminated. I use strcat (Buffer, "\r\n") to
>> append a carriage return\line feed to the string before outputting it
>> to a display

>Outputting a string to a display is not defined in C++, you know that,
>right? There is no such thing as "display" in C++.


Yes, and once again, the purpose was completeness. I wanted it
understood why I was appending the CR\LF combination.
> > where I can monitor what's being exchanged with another
>> service. But after the strcat the string in Buffer is terminated, not
>> with \r\n but with a \n and NO nul terminator.

>I think this is covered in the FAQ. See 5.8.

> > The carriage return is
>> dropped completely.

>> If this was output for a text file I'd think it was an expected
>> conversion. But all of this is still in memory.

>I'll believe you when I see the code.


strcpy (Buffer, "MAIL FROM: ");
m_From.GetWindo wText(Text, 512); // sorry if this is MFC
strcat (Buffer, Text); // up to this point the string is nul
// terminated

// Buffer is passed to a function but is still null
// terminated following the call

strcat(Buffer, "\r\n"); // after this operation the
// string is LF terminated with no
// nul


What is strlen(Buffer) vs. sizeof(Buffer)?


sizeof(Buffer) = 512
strlen(Buffer) := 50

Lots of room.

--
Lilith
Feb 27 '06 #5
Victor Bazarov wrote:
Outputting a string to a display is not defined in C++, you know that,
right? There is no such thing as "display" in C++.


There doesn't have to be, because that's covered in the C standard.

Section "5.2.2 Character display semantics" in 9899:1999.

:)

Feb 27 '06 #6

Lilith wrote:
What is strlen(Buffer) vs. sizeof(Buffer)?


sizeof(Buffer) = 512
strlen(Buffer) := 50

Lots of room.


Skirt the issue then, set buffer to all 0 before processing. Then if
it fails something is modifying it in a way you are not expecting and
you can look for it.

Feb 27 '06 #7

<ro**********@g mail.com> schrieb im Newsbeitrag
news:11******** **************@ i40g2000cwc.goo glegroups.com.. .

Lilith wrote:
>What is strlen(Buffer) vs. sizeof(Buffer)?


sizeof(Buffer) = 512
strlen(Buffer) := 50

Lots of room.


Skirt the issue then, set buffer to all 0 before processing. Then if
it fails something is modifying it in a way you are not expecting and
you can look for it.


does a strlen of 50 not kinda indicates the real length and that there is a
0 and a wrong "DISPLAY"?
Feb 27 '06 #8
Lilith wrote:
strcpy (Buffer, "MAIL FROM: ");
m_From.GetWindo wText(Text, 512); // sorry if this is MFC
strcat (Buffer, Text); // up to this point the string is nul
// terminated
Neither strcpy() nor strcat() have any mechanism to guard against
storing more characters than the destination array can hold.
// Buffer is passed to a function but is still null
// terminated following the call

strcat(Buffer, "\r\n"); // after this operation the
// string is LF terminated with no
// nul


How do you know? Are you by chance relying on the variable inspection
window of your debugger? That Microsoft thing has certain issues when
it comes to displaying strings. It cuts off strings that are too long,
and I think it basically just stuffs the text into its own control, so
that \r\n just becomes a line break. I haven't used it in a long time,
so I can't quite remember. If you want to be sure what's in that
character array, you should convert it yourself to printable form and
dump it to a debug trace function.

Oh, you do know that C++ has a string class, right?

Moreover, you do know that MFC has a CString class?

Moreover, you do know that the control you are using has a
GetWindowText() overload that will put data into a CString object?

void CWnd::GetWindow Text(CString& rString) const;

Why are you messing around with strcat instead of using the string type
provided by the framework in which you are making the GUI?

Idiot!

Feb 27 '06 #9
Kaz Kylheku wrote:
Victor Bazarov wrote:
Outputting a string to a display is not defined in C++, you know that,
right? There is no such thing as "display" in C++.

There doesn't have to be, because that's covered in the C standard.

Section "5.2.2 Character display semantics" in 9899:1999.

:)


How is that relevant? AFAIK, C++ Standard only refers to 9899:1990. :)
Feb 27 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2457
by: Jon | last post by:
using Borland Compiler. x = "this is a string" strcat(x,x) strcat(x,x) will produce "this is a stringthis is a stringthis is a stringthis is a stringt"
44
5807
by: Nicolas | last post by:
On most implementations of the standard C library, the functions that copy characters in a previously allocated buffer, like strcpy or strcat, are returning the pointer to that buffer. On my NetBSD system, man strcpy gives the following prototype : char *strcpy(char * restrict dst, const char * restrict src); What's the point in returning a pointer we already know before the call? Thank you in advance for an explanation.
81
7323
by: Matt | last post by:
I have 2 questions: 1. strlen returns an unsigned (size_t) quantity. Why is an unsigned value more approprate than a signed value? Why is unsighned value less appropriate? 2. Would there be any advantage in having strcat and strcpy return a pointer to the "end" of the destination string rather than returning a
8
539
by: ctara_shafa | last post by:
Hi, I have a following problem: I'm creating a list and one of the fields should contain the date. Firstly I ask the user for the year, month and day and then I'd like to collect all this data in one field. To do this I tried to concatenate those 3 numbers into one using strcat. A piece of code is as follows /*function to enter the date*/ char * date (void) {
9
3430
by: cicalese | last post by:
For starters, I am a C novice. I don't fully understand how strings work. I am running on a linux box. I compile w/ gcc. I have a string called 'myabqcommand' that is being overwritten when i use strcat() on some unrelated strings. For this code: char *myabqcommand; myabqcommand = strtok(x, "-");
87
5141
by: Robert Seacord | last post by:
The SEI has published CMU/SEI-2006-TR-006 "Specifications for Managed Strings" and released a "proof-of-concept" implementation of the managed string library. The specification, source code for the library, and other resources related to managed strings are available for download from the CERT web site at: http://www.cert.org/secure-coding/managedstring.html
12
2376
by: Eric Kaplan | last post by:
why the following code will crash? int main() { char* str = "aa"; strcat (str, "hello"); cout << str << "\n"; strcat (str, "you1"); cout << str << "\n";
0
9473
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9334
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...
0
9208
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...
1
6750
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
4569
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...
0
4824
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
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
2
2744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.