我有一个关于将一个字符数组的变量从一个函数传递到下一个函数的问题。
以下是涉及的代码示例:
int main( int argc, char** argv )
{
int value = 0;
int nCounter = 0;
FILE* fIn = NULL;
char * sLine = new char[MAX_FILENAME_SIZE];
char * sFileName = new char [MAX_FILENAME_SIZE];
char * s = new char [MAX_FILENAME_SIZE];
if ((fIn = fopen(ImgListFileName,"rt"))==NULL)
{
printf("Failed to open file: %s\n",ImgListFileName);
return nCounter;
}
while(!feof(fIn)){
//set the variables to 0
memset(sLine,0,MAX_FILENAME_SIZE*sizeof(char));
memset(sFileName,0,MAX_FILENAME_SIZE*sizeof(char));
memset(s,0,MAX_FILENAME_SIZE*sizeof(char));
//read one line (one image filename)
//sLine will contain one line from the text file
fgets(sLine,MAX_FILENAME_SIZE,fIn);
//copy the filename into variable s
strncpy(s, sLine, strlen(sLine)-1);
//put a \0 character at the end of the filename
strcat(sLine,"\0");
//create the filename
strcat(sFileName,s);
nCounter++;
fclose(fIn);
delete sLine;
delete sFileName;
delete s;
const int size = 60;
char path[size] = "path";
strcat(path,sFileName);
printf (path);
IplImage *img = cvLoadImage(path);
detect_and_draw(img);
cvWaitKey();
cvReleaseImage(&img);
cvDestroyWindow("result");
void detect_and_draw( IplImage* img )
{
More code that isn't involved....
cvSaveImage(sFileName, img);
现在,我尝试了以下方法:
void getFilename(char * sFileName)
{
printf("The filename is %s\n", sFileName);
return;
}
然后打电话给
char * S ="string"
getFilename(S);
cvSaveImage(S,img);
但是“字符串”被放入“文件名是:字符串”。
我该怎么做才能在 cvSaveImage(sFileName, img) 中使用 sFileName、char 数组?
在此先感谢您,如果您需要任何进一步的说明,请询问!