Thread: Strings and stuff

  1. #1
    Unregistered
    Guest

    Unhappy 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)

  2. #2
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    You can't just copy a string using
    vari.x="Donkey";

    Use strcpy()

  3. #3
    Unregistered
    Guest
    Thanks I'll try

  4. #4
    Unregistered
    Guest

    Question

    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

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    68
    [code]
    strcpy(var.x[1],"cow");
    [code]

  6. #6
    Unregistered
    Guest
    I love you lol

  7. #7
    Registered User
    Join Date
    Jul 2002
    Posts
    273

    Talking

    you couldn't possibly love him, you've only known him for at most an hour!
    always looking, make an offer. get me out of this place.

  8. #8
    Unregistered
    Guest
    goodpoint...I need a name too hmmmm

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fwrite can't write dynamic strings???
    By Devil Panther in forum C Programming
    Replies: 26
    Last Post: 05-19-2009, 02:18 AM
  2. Creating Strings from other stuff
    By Manitoadlet in forum C++ Programming
    Replies: 7
    Last Post: 09-10-2002, 06:07 PM
  3. damn strings
    By jmzl666 in forum C Programming
    Replies: 10
    Last Post: 06-24-2002, 02:09 AM
  4. Adding stuff to strings from files..
    By R@m0n in forum C++ Programming
    Replies: 4
    Last Post: 02-03-2002, 02:38 PM
  5. Strings and stuff
    By casanova0o7 in forum C++ Programming
    Replies: 4
    Last Post: 01-23-2002, 08:37 PM