#include%26lt;iostream.h%26gt;
#include%26lt;string.h%26gt;
void main()
{
char frase[20];
int letra;
char muestra[1];
char limpio[20];
int len;
cout%26lt;%26lt;"Frase? ";
cin%26gt;%26gt;frase;
len=strlen(frase);
strcpy(muestra,"");
for (letra=0;letra%26lt;=len-1;letra++)
{
strcpy(muestra,frase[letra]);
strcat(limpio,muestra);
cout%26lt;%26lt;limpio;
}
return;
}
it says that I cannot convert parameter 2 from 'char' to 'const char *' in the strcpy(muestra,frase[letra]); line, how can I fix that?
Could you check this c++ code for me?
well, strcpy() expects two character pointers as parameters/arguments. here muestra is a character pointer and frase is also a character pointer. but frase[letra], where letra is integer, refers to a character value rather than address. Thats the only reason.
But if I am correct, you are trying to copy(append) whatever frase string contains to limpio string, isn't it? If it is then , you could simply replace the for loop with following stmts.
..
..
cin%26gt;%26gt;frase;
strcat(limpio, frase); /* or strcpy(limpio, frase); assuming limpio is empty string */
cout%26lt;%26lt;limpio;
.....
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment