Thread: Im having a wired cast error.. HELP!

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    32

    Question Im having a wired cast error.. HELP!

    The error is below where there is an arrow describing the issue thank you for your time.

    #pragma inspect, symbols
    #pragma nolist
    #include <stdio.h>
    #include <string.h>
    #include <tal.h>
    #include <cextdecs(FILE_OPEN_,FILE_CLOSE_,FILE_GETINFO_,WRI TEX,READX)>
    #include <fcntl.h>
    #include <stdlib.h>
    #pragma list



    int x;

    main()
    {

    struct databse {
    char cust_num;
    char name[20];
    int address;
    char city[20];
    char state[20];
    };




    _cc_status cc;
    short fpointer ,error;
    char RecCust[75];
    struct databse customer;
    customer.cust_num = x;
    customer.address = 1234;
    customer.name;
    customer.city;
    customer.state;


    strcpy(RecCust,cust_num); <------- THIS WILL NOT ACCEPT AN IN HOWEVER I TRIED (CHAR)CUST_NUM, ALSO CHAR(CUST_NUM) BUT I GET AN ERROR.

    strcpy(customer.name, "Name");
    strcpy(customer.city, "City");
    strcpy(customer.state, "State");

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Database.cust_num is a single char which can store values only from -128 to +127

    If you want to get this extremely limited customer number out of the record you need to use:
    Code:
    int RecCust;
    
    RecCust = customer.cust_num;
    Either that or redefine your struct to something more sensible. I'm thinking you're going to want more than an int to store their address.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Your cust_num is a char? Is that what you want it to be, really? Char's have a very small range.

    Somehow, I expected to see a pic of a broken arm in a wired cast, instead of a plaster one.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Thanks for reading the introductory notes with the title
    << !! Posting Code? Read this First !! >>
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Mar 2011
    Posts
    32
    Sorry it was not the original error posted the wrong version? the error is below.

    Code:
    
    #pragma inspect, symbols
    #pragma nolist
    #include <stdio.h>
    #include <string.h>
    #include <tal.h>
    #include <cextdecs(FILE_OPEN_,FILE_CLOSE_,FILE_GETINFO_,WRITEX,READX)>
    #include <fcntl.h>
    #include <stdlib.h>
    #pragma list
    
    
    
    
    main()
    {
    
    struct databse {
      int cust_num;
      char name[20];
      int address;
      char city[20];
      char state[20];
    };
    
    
    
      
     	_cc_status cc;
    	short fpointer ,error;
    	char RecCust[85];
    	struct databse customer;
    	customer.cust_num = 1;
    	customer.address = 1234;
            customer.name;
            customer.city;
    	customer.state;
    	
    	
    	strcpy(customer.name, "Name");
    	strcpy(customer.city, "City");
    	strcpy(customer.state, "State");
    
      	
    	FILE_OPEN_("FILEKEY",7, &fpointer);
    
    	  strcpy(RecCust,customer.cust_num);   <---- Still have an error it doesn;t attach the int into the char ive tried               casting it still an error. 
    
     	  strcat(RecCust,"        ");
      	  strcat(RecCust, customer.name);
    Last edited by KMAN999; 03-14-2011 at 08:29 AM.

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    That's because you cannot strcpy() an integer.

    You are going to need sprintf() for that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Including The Right DLLs
    By bumfluff in forum Game Programming
    Replies: 8
    Last Post: 12-28-2006, 03:32 AM
  2. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  3. Converting Double to Float
    By thetinman in forum C++ Programming
    Replies: 7
    Last Post: 06-17-2006, 02:46 PM
  4. errors in class(urgent )
    By ayesha in forum C++ Programming
    Replies: 1
    Last Post: 11-10-2001, 10:14 PM
  5. errors in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 06:51 PM

Tags for this Thread