[Wolves] C++ woes

Jon Farmer wolves at mailman.lug.org.uk
Mon Sep 23 12:15:01 2002


Hi All

Anyone help me with this? BAsically I am pulling some records from MYSQL and
want to do a replace on the Telephone field as I loop through the return
records.

In PHP i would do something like

$telephone = str_replace(" ","",$row[1]);

Any ideas on how to do it in C++, below is what I have so far

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include </usr/include/g++/iostream>
#include </usr/local/include/mysql/mysql.h>

int main(void)
{

MYSQL mysql;
int count;
int time;
MYSQL_RES *mysqlresult;
MYSQL_ROW trow;
char *telephone;

mysql_init(&mysql);
if
(!mysql_real_connect(&mysql,"cppdb.localhost","username","password","db",0,N
ULL,0))
{
    fprintf(stderr, "Failed to connect to database: Error: %s\n",
mysql_error(&mysql));
}
mysql_query(&mysql,"select ID, Telephone, CustomerRef from orders where
Status ='O'");
mysqlresult = mysql_store_result(&mysql);
while(trow = mysql_fetch_row(mysqlresult)){
        printf("Row 1: %s\n",trow[1]);
}
return 0;
}

int MailMessage(char *To, char *From, char *Subject, char *Message)
{
   FILE *mail;
   char command[512]="";
   strcpy(command,"/usr/lib/sendmail   ");
   strcat(command,To);
   mail = popen(command,"w");

   if (mail == NULL)
      return -1;

   fprintf(mail,"From: %s \n",From);
   fprintf(mail,"Subject: %s\n",Subject);
   fprintf(mail,"%s\n.\n",Message);
   pclose(mail);

   return 0;
}


TIA

Jon

--
Jon Farmer
Systems Programmer, Entanet www.enta.net
Tel 01952 428969
PGP Key available, send email with subject: Send PGP Key