[NTLUG:Discuss] C pointer questions
Paul Ingendorf
pauldy at wantek.net
Wed Nov 27 10:04:22 CST 2002
>From what I read in the question you are looking for the strings functions
#include <string.h>
char *a = " a test.", *b = "This is";
b = strcat( b, a );
printf(b);
Should print:
This is a test
Hope that helps you.
Quoting Fred James <fredjame at concentric.net>:
> What I am trying to do is append one body of text to another (B to A),
>
> both of which are referenced by pointers, and then copy A to B so the
> result would be the same as if I had inserted A at the top of B (because
>
> I am going to use B in my final fwrite()). Any suggestions would be
> most apprecated. Full code upon request.
>
> Here is a snippet of the orginal C code, which works by the way:
> [original code begins]
> sprintf(mailCmd,
> "/usr/sbin/mailx -s '%s' %s",
> pSubject,
> pRecipientList);
>
> errno = 0;
>
> if ( (pMailPipe = popen (mailCmd, "w")) != NULL )
> {
> if ( fwrite (pMessage, strlen (pMessage), 1, pMailPipe)
> == strlen (pMessage) )
> {
> errorStatus = pclose(pMailPipe);
> }
> else
> {
> errorStatus = errno;
> (void) pclose (pMailPipe);
> }
> }
> else
> {
> errorStatus = errno;
> }
>
> return errorStatus;
> [original code ends]
>
> Here is the same snippet plus some stuff I am trying to add (at the
> top), without too much success so far:
> [modified code begins]
> sprintf(AppendCmd, "echo \"~|uuencode '%s'\" > '%s'", pAttachment,
>
> pAttachment);
> system(AppendCmd);
> sprintf(AppendCmd, "cat '%s' >> '%s'", pMessage, pAttachment);
> system(AppendCmd);
> pMessage = pAttachment;
>
> sprintf(mailCmd,
> "/usr/sbin/mailx -s '%s' %s",
> pSubject,
> pRecipientList);
>
> errno = 0;
>
> if ( (pMailPipe = popen (mailCmd, "w")) != NULL )
> {
> if ( fwrite (pMessage, strlen (pMessage), 1, pMailPipe)
> == strlen (pMessage) )
> {
> errorStatus = pclose(pMailPipe);
> }
> else
> {
> errorStatus = errno;
> (void) pclose (pMailPipe);
> }
> }
> else
> {
> errorStatus = errno;
> }
>
> return errorStatus;
> }
> [modified code ends]
>
>
> --
> small is beautiful
>
>
> _______________________________________________
> https://ntlug.org/mailman/listinfo/discuss
>
--
-->> mailto:pauldy at wantek.net
-->> http://www.wantek.net/
Running ....... Cos anything else would be a waste...
`:::\' ....... ......
::: * `::. ::\'
::: .:: .:.::. .:: .:: `::. :\'
::: :: :: :: :: :: :::.
::: .::. .:: ::. `::::. .:\' ::.
:::.....................::\' .::::..
More information about the Discuss
mailing list