Problems coping a char to a char using strcpy

This is a discussion on Problems coping a char to a char using strcpy within the C++ Programming forums, part of the General Programming Boards category; Hi everyone! Im new in this forum! Im having problems with the funtion "strcpy" I used it to copy what ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    2

    Question Problems coping a char to a char using strcpy

    Hi everyone! Im new in this forum!

    Im having problems with the funtion "strcpy"

    I used it to copy what the char var "sex" have to the char var "nuevo->sexo", both are char of 1 byte, so i dont know the reason of this error:

    Help will be really apreciate since is a proyect for tomorrow, is the unique wierd error that im having and i dont know how to solved it.

    Here the funtion and my header:
    Code:
    //HeaderBegin
    #include <stdio.h>
    #include <stdlib.h>
    #include<iostream>
    #include<conio.h>
    #include<fstream>
    #include<ctime>
    #include <string.h>
    #include <stdlib.h>
    #include <windows.h>
    using namespace std;
    
    //int cl=0; // odio esta variable
    
    long sesion=0; // pronto morira la variable de arriba, muahahahaha!
    char n[50],a[50];
    
    struct tfecha{
           int dd;
           int mm;
           int aa;
           };
           
         
         time_t tSac = time(NULL);  // instante actual
        struct tm* tmP = localtime(&tSac); // time 
        
       /*  hoy.dd= tmP->tm_mday;
         hoy.mm= tmP->tm_mon+1;
         hoy.aa= tmP->tm_year+1900; */       
    
         
    struct cliente{ // Nota importante: cada ves que sea cambiada esta structura debe borrase la base de datos
           long cedula;
          // int admin;
           int deleted;
           int pin;
           char nombre[50];
           char apellido[50];
           char sexo;
           double capital;
           tfecha fapertura;
           cliente *sig;
           }client,verifc, *nuevo, *lista=NULL, *aux,*ant,*aux1;
           
    struct administrador{ // Nota importante: cada ves que sea cambiada esta structura debe borrase la base de datos
           int cedula;
          // int admin;
          // int deleted;
           int pin;
         //  char nombre[50];
          // char apellido[50];
          // char sexo;
          // double capital;
           tfecha fapertura;
           administrador *sig;
           }admin, *nuevoa, *listaa=NULL, *auxa, *anta, *aux1a;
           
           
    void wait(long seconds)
    {
         seconds = seconds * 1000;
         Sleep(seconds);
    }       
    
    // HeaderEnd
    
    
    void NuevaCuenta()
    {
         int errur,errer;
         char ci[8],cap[9],pp[4];
         char nomb[50], apell[50], sex;
         int k=0;
             int c;
         int ex=0,edor=0;
         // fecha
         time_t tSac = time(NULL);       // instante actual
         struct tm* tmP = localtime(&tSac); // time
    
         //fechda end
         edor=0; // vadiable pada chequead pod errores, la variable es util y funcional
      //   ofstream archo;
        // ofstream archi; 
        /* archo.open("bancodata.db",ios::app);
         archo.write((char*)& client,sizeof(client));
         archo.close(); */
         //archi.open("bancodata.db",ios::app); //archi.open("bancodata.db",ios::app|ios::in|ios::out); // archi.open("bancodata.db",ios::in|ios::out);  archi.open("bancodata.db",ios::app);
         nuevo= new cliente;
         
         ex=0; c=0;
         do{
          edor++;                                   
         system("cls");
         cout<<"\n\t-------------------------------------------------------------";
         cout<<"\n\t- BANCO MANDANTE -\n\n\t> APERTURA DE UNA CUENTA\n\n\tPorfavor ingrese los datos requeridos para apertura su cuenta:";
         cout<<"\n\t-------------------------------------------------------------";
         cout<<"\n\tFecha de hoy: "<<tmP->tm_mday<<" / "<<tmP->tm_mon+1<<" / "<<tmP->tm_year+1900;
         if(edor>1)
         {
                   cout<<"\n\n\t[!] Error: Ya existe un usuario con la cedula indicada o\n\tah ingresado una cedula invalida.";
         }
         
         cout<<"\n\n\t]Digite su cedula: \t\t";
         cin>>ci; 
         c=atoi (ci);
         // disponible begin       
        if (c!=0) ex=Disponible(c);
        else ex=0;
        
        //if(c==0) ex=0; // linea de mas?? no me crees? revisa lo de arriba, ves? no ves? CIEGO!
       // disponible end
         }while(ex==0);
         //client.cedula=c;
         nuevo->cedula=c;
        // cout<<c;
         
         cout<<"\n\t]Su nombre: \t\t";
          //  cin>>client.nombre;
         cin>>nomb;
         //nuevo->nombre=nomb;
         strcpy (nuevo->nombre,nomb);
         cout<<"\n\t]Su Apellido: \t\t";
         //cin>>client.apellido;
         cin>>apell;
         //nuevo->apellido=apell;
         strcpy (nuevo->apellido,apell);
         cout<<"\n\t]Sexo (F)emenino/(M)asculino: \t\t";
         //cin>>client.sexo;
         cin>>sex;
         //nuevo->sexo=sex;
         strcpy (nuevo->sexo, sex); // Line of the error
         errer=0;
         do{
            if (errer>0) cout<<"\n\t [!] Error: Monto ingresado es invalido";
            cout<<"\n\t]Monto de Apertura(BSF VEF): \t\t";
            //cin>>client.capital;
            cin>>cap;
            //client.capital = atoi (cap);
            nuevo->capital= atoi (cap);
            if(nuevo->capital==0) errer++;
         }while(nuevo->capital==0);
         
         errur=0;
         do{
            if (errur>0) cout<<"\n\t [!] Error: pin ingresado incorrectamente.";                   
            cout<<"\n\tIngrese el pin que usara para ingresar al sistema(4 digitos NUMERICOS)\n\t]Pin: \t\t";
            //cin>>client.pin;
            cin>>pp;
            //client.pin = atoi (pp);
            nuevo->pin = atoi (pp);
            if (nuevo->pin==0) errur++;
         }while(nuevo->pin==0);
         
         //client.admin=1; // 1 = usuario, 2 = administrador
        // client.deleted=0; // cliente no borrado 
        nuevo->deleted=0;
         system("cls");
         cout<<"\n\n\tSu cuenta ah sido registrado exitosamente!\n\n\tRegresando al Menu Principal...";
         
         nuevo->fapertura.dd=tmP->tm_mday; // posible problema
         nuevo->fapertura.mm=tmP->tm_mon+1;
         nuevo->fapertura.aa=tmP->tm_year+1900; 
        
            
        // archi.write((char*)& client,sizeof(client));
        // archi.close();
         getch();
       //  cl++;
    }
    The error obtained when i try compile is:

    In function `void NuevaCuenta()':
    invalid conversion from `char' to `char*'
    initializing argument 1 of `char* strcpy(char*, const char*)'
    `char' to `const char*'
    initializing argument 2 of `char* strcpy(char*, const char*)
    '

    Others details: Im using the compiler Dev C/C++

    PD: Sorry if my english isnt good.
    Last edited by iKlys++; 02-10-2011 at 04:45 PM.

  2. #2
    Registered User
    Join Date
    Feb 2011
    Posts
    2
    Ok i solved my problem.

    I update all my headers to C++ and now i can compare and igualed strings and chars vars.


  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    2,541
    strcpy is for coping strings not a single char.

    Tim S.

  4. #4
    -bleh-
    Join Date
    Aug 2010
    Location
    somewhere in this universe
    Posts
    452
    just use the <string> class.
    "All that we see or seem
    Is but a dream within a dream." - Poe

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The UNIX System Interface
    By rrc55 in forum C Programming
    Replies: 1
    Last Post: 10-20-2009, 05:56 PM
  2. Char Help! "Packing " bits to a signle unsigned char
    By xxrexdartxx in forum C Programming
    Replies: 7
    Last Post: 10-11-2009, 04:45 AM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  5. Strings are V important...
    By NANO in forum C++ Programming
    Replies: 15
    Last Post: 04-14-2002, 11:57 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21