Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Problem- strcat with char and char indexed from char array

Reply
Thread Tools

Problem- strcat with char and char indexed from char array

 
 
aldonnelley@gmail.com
Guest
Posts: n/a
 
      04-20-2006
Hi there.

I'm just learning c++, and this is driving me nuts.

I'm trying to save image files generated in a for loop with a filename
built using strcat with:
- a char base file name
+ a character to identify the individual files that is indexed from a
char array by the int index of the for loop
+ a char file extension.

I keep getting a "cannot convert 'int' to 'const char'" error on the
line where I'm trying to strcat the character I've indexed from the
char array to the base file name. (script attached)

Can anyone tell me what is happening here, and how to fix it?

Cheers, Al.

//code starts

for(i=0;i<(faces ? faces->total:0); i++ )
{
const char arr[25] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y' };
CvRect* r = (CvRect*)cvGetSeqElem( faces, i );

pt1.x = ( r->x + 0.08*(r->width));
pt2.x = ( r->x + 0.92*(r->width));
pt1.y = (r->y );
CvRect reg;
reg.x = pt1.x;
reg.y = pt1.y;
reg.width = abs( pt2.x - pt1.x);
reg.height = (r->height);
image->roi = NULL;
cvSetImageROI (image, reg);
region = cvCreateImage(cvSize (reg.width, reg.height), image->depth,
image->nChannels);
cvCopy (image, region, 0);

char fileindex = arr[i];
fileindex = ( const char ) fileindex;
char fileName[50] = "output";
char str[60];
strcpy (str, fileName);
strcat (str, fileindex); //compiler doesn't like this at
all...
strcat (str, ".jpg");
puts(str);
cout << str << endl;
cvSaveImage( str, region);
cvResetImageROI(image);
cvRectangle(image, pt1, pt2, CV_RGB(255, 0, 0), 3, 8, 0);

//code ends

 
Reply With Quote
 
 
 
 
Peter Jansson
Guest
Posts: n/a
 
      04-20-2006
<(E-Mail Removed)> skrev i meddelandet
news:(E-Mail Removed) oups.com...
> Hi there.
>
> I'm just learning c++, and this is driving me nuts.
>
> I'm trying to save image files generated in a for loop with a filename
> built using strcat with:
> - a char base file name
> + a character to identify the individual files that is indexed from a
> char array by the int index of the for loop
> + a char file extension.
>
> I keep getting a "cannot convert 'int' to 'const char'" error on the
> line where I'm trying to strcat the character I've indexed from the
> char array to the base file name. (script attached)
>
> Can anyone tell me what is happening here, and how to fix it?
>
> Cheers, Al.
>
> //code starts
>
> for(i=0;i<(faces ? faces->total:0); i++ )
> {
> const char arr[25] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
> 'j', 'k', 'l', 'm', 'n', 'o',
> 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y' };
> CvRect* r = (CvRect*)cvGetSeqElem( faces, i );
>
> pt1.x = ( r->x + 0.08*(r->width));
> pt2.x = ( r->x + 0.92*(r->width));
> pt1.y = (r->y );
> CvRect reg;
> reg.x = pt1.x;
> reg.y = pt1.y;
> reg.width = abs( pt2.x - pt1.x);
> reg.height = (r->height);
> image->roi = NULL;
> cvSetImageROI (image, reg);
> region = cvCreateImage(cvSize (reg.width, reg.height), image->depth,
> image->nChannels);
> cvCopy (image, region, 0);
>
> char fileindex = arr[i];
> fileindex = ( const char ) fileindex;
> char fileName[50] = "output";
> char str[60];
> strcpy (str, fileName);
> strcat (str, fileindex); //compiler doesn't like this at
> all...
> strcat (str, ".jpg");
> puts(str);
> cout << str << endl;
> cvSaveImage( str, region);
> cvResetImageROI(image);
> cvRectangle(image, pt1, pt2, CV_RGB(255, 0, 0), 3, 8, 0);
>
> //code ends
>


Hello,

A suggestion: Change the prolematic code into something like the following;

#include <sstream>
#include <iostreama>
//.... Your beginning code here...
std:stringstream o;
o<<"output"<<arr[i]<<".jpg";
std::cout<<o.str()<<std::endl;
cvSaveImage(o.str().c_str(),region);
// .... Your ending code here...


Regards,

Peter Jansson
http://www.p-jansson.com/
http://www.jansson.net/


 
Reply With Quote
 
 
 
 
Peter Jansson
Guest
Posts: n/a
 
      04-20-2006

<(E-Mail Removed)> skrev i meddelandet
news:(E-Mail Removed) oups.com...
> Hi there.
>
> I'm just learning c++, and this is driving me nuts.
>
> I'm trying to save image files generated in a for loop with a filename
> built using strcat with:
> - a char base file name
> + a character to identify the individual files that is indexed from a
> char array by the int index of the for loop
> + a char file extension.
>
> I keep getting a "cannot convert 'int' to 'const char'" error on the
> line where I'm trying to strcat the character I've indexed from the
> char array to the base file name. (script attached)
>
> Can anyone tell me what is happening here, and how to fix it?
>
> Cheers, Al.
>
> //code starts
>
> for(i=0;i<(faces ? faces->total:0); i++ )
> {
> const char arr[25] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
> 'j', 'k', 'l', 'm', 'n', 'o',
> 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y' };
> CvRect* r = (CvRect*)cvGetSeqElem( faces, i );
>
> pt1.x = ( r->x + 0.08*(r->width));
> pt2.x = ( r->x + 0.92*(r->width));
> pt1.y = (r->y );
> CvRect reg;
> reg.x = pt1.x;
> reg.y = pt1.y;
> reg.width = abs( pt2.x - pt1.x);
> reg.height = (r->height);
> image->roi = NULL;
> cvSetImageROI (image, reg);
> region = cvCreateImage(cvSize (reg.width, reg.height), image->depth,
> image->nChannels);
> cvCopy (image, region, 0);
>
> char fileindex = arr[i];
> fileindex = ( const char ) fileindex;
> char fileName[50] = "output";
> char str[60];
> strcpy (str, fileName);
> strcat (str, fileindex); //compiler doesn't like this at
> all...
> strcat (str, ".jpg");
> puts(str);
> cout << str << endl;
> cvSaveImage( str, region);
> cvResetImageROI(image);
> cvRectangle(image, pt1, pt2, CV_RGB(255, 0, 0), 3, 8, 0);
>
> //code ends



Hello again,

Just a follow-up; strcat expects two char* arguments. One of the arguments
can't be just char.

Regards,

Peter Jansson
http://www.p-jansson.com/
http://www.jansson.net/


 
Reply With Quote
 
aldonnelley@gmail.com
Guest
Posts: n/a
 
      04-20-2006
Champion!

Works like a dream.

Thanks Peter.

Cheers, Al.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Prefix of indexed name must be an array. Olaf VHDL 2 05-04-2007 05:44 AM
strcat syntax with int and char 2005 C Programming 4 11-06-2006 09:42 PM
strcat syntax with int and char 2005 C++ 7 11-06-2006 06:26 PM
(const char *cp) and (char *p) are consistent type, (const char **cpp) and (char **pp) are not consistent lovecreatesbeauty C Programming 1 05-09-2006 08:01 AM
indexed property for array does not see my bean :-( milkyway Java 2 12-26-2004 03:04 PM



Advertisments