[NTLUG:Discuss] C pointer questions
Fred James
fredjame at concentric.net
Tue Nov 26 10:03:52 CST 2002
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
More information about the Discuss
mailing list