🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: alt.comp.lang.learn.c-c++
8 messages
8 total messages Started by News Tue, 03 Oct 2000 00:00
String manipulation
#481
Author: News
Date: Tue, 03 Oct 2000 00:00
16 lines
1464 bytes
I need some help for string manipulation (without CString class).
I know basics of C++, but never used strings.
For example I need a function for appending a backslash after a directory
name:

VOID WINAPI AppendSlash(LPTSTR *lpFileName)
{
 len = lstrlen(*lpFileName) + 1;
 if (len > 0 && szBuffer[len] != '\\')
 {
  // Modify string by adding a backsslash
 }
}

Thanks,
Jef Driesen
Re: String manipulation
#482
Author: Philip Staite
Date: Tue, 03 Oct 2000 00:00
34 lines
2137 bytes
News wrote:

> I need some help for string manipulation (without CString class).
> I know basics of C++, but never used strings.
> For example I need a function for appending a backslash after a directory
> name:
>
> VOID WINAPI AppendSlash(LPTSTR *lpFileName)
> {
>  len = lstrlen(*lpFileName) + 1;

You realize that len will never be 0 now.  Even when lpFileName is "" len
will be 1.

>  if (len > 0 && szBuffer[len] != '\\')

The first test, len>0 will always be true.  What is szBuffer?  If it
duplicates what lpFileName is pointing at, then looking at [len] is probably
not what you want to do.  Suppose lpFileName points to "foo.txt" then strlen
will return 7.  Now, lpFileName[6] is 't' and lpFileName[7] is the
terminating NULL.  You've got len set to point at in-effect lpFileName[8]
which is undefined.

>  {
>   // Modify string by adding a backsslash
>  }
> }

If you know lpFileName points to memory that is long enough to accept the
additional character, why not just do something like:

int n = strlen(lpFileName);
if( n && ( lpFileName[n-1] != '\\' ) )
  strcat( lpFileName, "\\" );
Re: String manipulation
#483
Author: Pete G.
Date: Tue, 03 Oct 2000 00:00
31 lines
2095 bytes
Use strcat (szBuffer, "\\");
By the way, your check for an existing '\\' is checking too far into the
string.  The value you are computing for len is adding 1 to include the
NULL.  The offset into the string for the last character should be
lstrlen(*lpFileName) - 1;
Also, how did you get from *lpFileName to szBuffer?  Also, the syntax you
are using would indicate that you are passing a pointer to a pointer to the
string in question.  Is this your actual intent?
Pete

"News" <jef_driesen@hotmail.com> wrote in message
news:39da0385.0@news.ruca.ua.ac.be...
> I need some help for string manipulation (without CString class).
> I know basics of C++, but never used strings.
> For example I need a function for appending a backslash after a directory
> name:
>
> VOID WINAPI AppendSlash(LPTSTR *lpFileName)
> {
>  len = lstrlen(*lpFileName) + 1;
>  if (len > 0 && szBuffer[len] != '\\')
>  {
>   // Modify string by adding a backsslash
>  }
> }
>
> Thanks,
> Jef Driesen
>
>
>
Re: String manipulation [OFF-TOPIC]
#484
Author: Pablo�
Date: Tue, 03 Oct 2000 00:00
20 lines
1902 bytes
News wrote in message <39da0385.0@news.ruca.ua.ac.be>...
>I need some help for string manipulation (without CString class).
>I know basics of C++, but never used strings.
>For example I need a function for appending a backslash after a directory
>name:



<Pablo>
Unfortunately this question is off-topic for alt.comp.lang.learn.c-c++ .  In
the future please restrict your questions to those that pertain to the core
C and C++ languages as defined by the appropriate ISO/ANSI standards
organizations.

With that being said, since you are obviously programming on Windows, you
can use the Win32 API function PathAddBackslash () to do what you want. Of
course, this assumes that you are willing to link in shlwapi32.lib into your
application.
</Pablo>
Re: String manipulation [OFF-TOPIC]
#485
Author: Joe O'Leary
Date: Tue, 03 Oct 2000 00:00
23 lines
1939 bytes
"Pablo�" wrote
>
> News wrote
> >I need some help for string manipulation (without CString class).
> >I know basics of C++, but never used strings.

> <Pablo>
> Unfortunately this question is off-topic for
alt.comp.lang.learn.c-c++ .  In
> the future please restrict your questions to those that pertain to
the core
> C and C++ languages as defined by the appropriate ISO/ANSI standards
> organizations.

The poster's question not at all off topic for
alt.comp.lang.learn.c-c++.

String manipulation is one of the more basic things a person learning
the language encounters.  And since the ISO/ANSI standard library now
includes a string class, it is even more relevant

Joe
Need you guys' help!
#486
Author: Yanxia Liu
Date: Tue, 03 Oct 2000 00:00
22 lines
1778 bytes
Hi,

I met a very strange problem when I tried to use C++ via MFCAppWizard to
create a first program. I followed the instruction to type in a single line
of code:

pC->TextOut(50,50,"Hello!",10);

It was compiled and builed. And it created an executive file. But it didn't
allow me to execute it. When I tried to execute the hello.exe file, a message
window was jumped. It said::"This program has performed an illegal operation
and will be shut down".

I ran the same program in other computer. It works very well. Nothing
happened.

What's wrong about my computer or my program? I appreciate you very much for
you time and your help.

Cheerio,

YL
Re: Need you guys' help!
#487
Author: Josh Sebastian
Date: Tue, 03 Oct 2000 00:00
38 lines
2194 bytes
On Tue, 03 Oct 2000 17:12:39 -0400, Yanxia Liu <yliu6@eos.ncsu.edu>
wrote:

>Hi,
>
>I met a very strange problem when I tried to use C++ via MFCAppWizard to
>create a first program.

MFC is off-topic.

> I followed the instruction to type in a single line
>of code:
>
>pC->TextOut(50,50,"Hello!",10);

Did you (or the framework) allocate memory for pC?

>
>It was compiled and builed. And it created an executive file. But it didn't
>allow me to execute it. When I tried to execute the hello.exe file, a message
>window was jumped. It said::"This program has performed an illegal operation
>and will be shut down".

But your program *did* run. While it was running, it performed an
illegal action, so the OS decieded to shut it down.

>
>I ran the same program in other computer. It works very well. Nothing
>happened.

Memory access violations are not always repeatable with different
computers (or even on the same computer).
_______

"Yields falsehood when preceded by its quotation" yields falsehood when preceded by its quotation.

Josh Sebastian
<curien@earthlink.net>
Re: Need you guys' help!
#488
Author: Nick Lawrence
Date: Tue, 03 Oct 2000 00:00
46 lines
2514 bytes
You probably have a pointer problem.

If this is the only real line of code in your program, I would start by
checking to see that pC is initalized correctly or points to a valid object.

Otherwise you may have to find a debugger and step through your code. :)

Memory problems and uninitalized data often do not show up the same on
different machines....It may 'just happen' to work for the time being on
that other machine.

Its also possible (although less likely) that you have an inconsistancy in
the code you compiled and the DDL's on your machine.

Yanxia Liu <yliu6@eos.ncsu.edu> wrote in message
news:39DA4BC7.3EF28AC3@eos.ncsu.edu...
> Hi,
>
> I met a very strange problem when I tried to use C++ via MFCAppWizard to
> create a first program. I followed the instruction to type in a single
line
> of code:
>
> pC->TextOut(50,50,"Hello!",10);
>
> It was compiled and builed. And it created an executive file. But it
didn't
> allow me to execute it. When I tried to execute the hello.exe file, a
message
> window was jumped. It said::"This program has performed an illegal
operation
> and will be shut down".
>
> I ran the same program in other computer. It works very well. Nothing
> happened.
>
> What's wrong about my computer or my program? I appreciate you very much
for
> you time and your help.
>
> Cheerio,
>
> YL
>
>
>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads