Hi,
I'm writing pretty much my first code with individual functions ever, and I've run into a couple of issues when I try to compile it. There are 6 or so functions, but the error is the exact same for all of them, so I've only included one example here. [Also, I've tested the functions individually, but then I had the return statement as "return 0", unlike now.]
Here's the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
char key(char mystring[100])
{
char alphabet[81]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!?0123456789.,:;/\()@#$%^&*_-";
char alpha[100];
alpha[0]=mystring[0];
int count=1; int i;int j;int k;
int length = strlen(mystring);
int alphalength;
int alphabetlength =strlen(alphabet);
cout << length<<endl;
for(i=1;i<=length;i++)
{
k=0;
alphalength = strlen(alpha);
for(j=0;j<=alphalength;j++)
{
if(alpha[j]==mystring[i])
k=k+1;
}
if(k==0)
{
alpha[count]=mystring[i];
count=count+1;
}
else
count=count;
}
for(i=0;i<=alphabetlength;i++)
{
k=0;
alphalength = strlen(alpha);
for(j=0;j<=alphalength;j++)
{
if(alpha[j]==alphabet[i])
k=k+1;
}
if(k==0)
{
alpha[count]=alphabet[i];
count=count+1;
}
else
count=count;
}
return alpha;
}
|
The goal is that it returns an array of characters which will be used by other functions eventually. In my separate test, I made it print this array, and that worked just fine, but this argument thing doesn't.
Here is the error I get when I try to compile (among a couple others) [Note, the line marking is not right here, the error hits in at the return line, not what it says in the error message below.]:
1 2 3 4
|
g++ message.cpp
message.cpp: In function ‘char key(char*)’:
message.cpp:110:10: error: invalid conversion from ‘char*’ to ‘char’ [-fpermissive]
message.cpp:67:8: warning: address of local variable ‘alpha’ returned [enabled by default]
|
Also, I don't know how big a deal the last warning line is, any input is much appreciated!
Thanks!