-
Strings and stuff
Here the problem guys... I am just comming back into programming with c++. Long vacation, or boredom of it, take your pick. Anyhow, I am trying to make a program the randomly puts three words together Ex: Moose Plucking Farmer...Dont ask I am weird with practice lol. Anyhow I cant seem to get it too run right and I just read the strings tutorial over 3 times straight and have honostly searched the boreds...PLEASE someone help me. (MY errors are at the bottom..my compiler is msvc++)
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
struct num{
int xa;
int ya;
int za;
};
struct chars{
char x[10];
char y[10];
char z[10];
};
int func();
int main()
{
srand((unsigned)time(NULL));
num run;
chars vari;
run.xa=rand()%3+1;
run.xa=rand()%3+1;
run.xa=rand()%3+1;
func();
cout<<vari.x;
cout<<" ";
cout<<vari.y;
cout<<" ";
cout<<vari.z;
cout<<" ";
return 0;
}
int func(){
num run;
chars vari;
if(run.xa==1){
vari.x="Donkey";
}
if(run.xa==2){
vari.x="Cow";
}
if(run.xa==3){
vari.x="moose";
}
if(run.ya==1){
vari.y="plucking";
}
if(run.ya==2){
vari.y="kissing";
}
if(run.ya==3){
vari.y="bucking";
}
if(run.za==1){
vari.z="candy";
}
if(run.za==2){
vari.z="Porkchop";
}
if(run.ya==3){
vari.z="carrot";
}
return 0;
}
--------------------Configuration: Cpp2 - Win32 Debug--------------------
Compiling...
Cpp2.cpp
C:\My Documents\Cpp2.cpp(37) : error C2440: '=' : cannot convert from 'char [7]' to 'char [10]'
There is no context in which this conversion is possible
C:\My Documents\Cpp2.cpp(40) : error C2440: '=' : cannot convert from 'char [4]' to 'char [10]'
There is no context in which this conversion is possible
C:\My Documents\Cpp2.cpp(43) : error C2440: '=' : cannot convert from 'char [6]' to 'char [10]'
There is no context in which this conversion is possible
C:\My Documents\Cpp2.cpp(46) : error C2440: '=' : cannot convert from 'char [9]' to 'char [10]'
There is no context in which this conversion is possible
C:\My Documents\Cpp2.cpp(49) : error C2440: '=' : cannot convert from 'char [8]' to 'char [10]'
There is no context in which this conversion is possible
C:\My Documents\Cpp2.cpp(52) : error C2440: '=' : cannot convert from 'char [8]' to 'char [10]'
There is no context in which this conversion is possible
C:\My Documents\Cpp2.cpp(55) : error C2440: '=' : cannot convert from 'char [6]' to 'char [10]'
There is no context in which this conversion is possible
C:\My Documents\Cpp2.cpp(58) : error C2440: '=' : cannot convert from 'char [9]' to 'char [10]'
There is no context in which this conversion is possible
C:\My Documents\Cpp2.cpp(61) : error C2440: '=' : cannot convert from 'char [7]' to 'char [10]'
There is no context in which this conversion is possible
Error executing cl.exe.
Cpp2.exe - 9 error(s), 0 warning(s)
-
You can't just copy a string using
vari.x="Donkey";
Use strcpy()
-
-
Say could you give me an example of how I might use strcpy()
in this program...I would REALY appriciate it.. (I hate to be a nag but I also hate not being do something due to lack of knowledge) thanks
-
[code]
strcpy(var.x[1],"cow");
[code]
-
-
you couldn't possibly love him, you've only known him for at most an hour!
-
goodpoint...I need a name too hmmmm