You are here:

C++/a compiling error

Advertisement


Question
hello
sorry for taking your time.
I have read a program for making subsets of a set,but I have a compiling error:
strcat(str,mainset[i]);
that can not change int to const char.
please help me in this error and tell me which changes should I make.
c++ version:4.5 for windows

my program:


#include<iostream.h>
#include<string.h>
#include<conio.h>
#include<stdio.h>

void subset(char [],char [],int);

main()
{
int j=0;
char set[15];
cout<<"enter the set to take subsets for:\n";
cin>>set;
subset(set," ",j);
cout<<endl;
getch();
return 0;
}

void subset(char mainset[],char calledset[],int i)
{
 int length=strlen(mainset);
 char str[15];
 if(i==length){
 cout<<"{"<<calledset<<"}"<<"\t";
 return;}
 //-------------------------------------------
 strcpy(str,calledset);


 strcat(str,mainset[i]);



 subset(mainset,str,i+1);
 //-------------------------------------------
 strcpy(str,calledset);
 strcat(str," ");
 subset(mainset,str,i+1);
}



take care of yourself and goodbye.

Answer
Dear Sara,
Thankyou for your question. Well, first of all
you should make the changes later, let me comment
on the main error why your program is not running.

Please check the prototype of the function which
you have given like

void subset( char [], char [], int )

and in the function call you are sending something
like

subset( madeset, "" , j )

It is giving me a mismatch error, an array doesnt
compensate for a null space. So i guess you should
better remove this error. Secondly your array wont
take the input correct. You've declared a single
dimensional array and you have declared it like this

char a[15]

cout<<"enter the input:";
cin>>a;

it would only interpret it as a single character your
whole set wouldnt be entered, you need a loop or some
condition, that how many elements you need to enter.
I guess first remove these errors, and let me know if
you cant get the logic working still.

Hope this helps,
Regards
Professional

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Professional

Expertise

I can answer any question about functions,pointers,structures,object oriented programming basics of classes and data structures.My strong field is structured programming.

Experience

I have got 2 years experiece under C . I am able to answer about the structured concepts pointers to a little extent,OOP concepts. I have also experience in data Strucutres like Linked List, Stacks , Queues, Heaps, B Trees, Red Black Trees. I will try to satisfy with my knowledge. I am the Student of an expert here Martin, what i have learnt today, i just owe my every knowledge to him. He is the greatest.

©2016 About.com. All rights reserved.