c error

This is a discussion on c error within the C Programming forums, part of the General Programming Boards category; Hi all, I have a program that I'm trying to write. I get an error that I don't know how ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    34

    c error

    Hi all,
    I have a program that I'm trying to write. I get an error that I don't know how to correct. Can anyone tell me where my error is? I'm using Borland 4.5 and the error states "cannot covert char* to char in sales function().
    This is the portion of the program and the error comes up on the line....trans_descript[trans_count]=descript
    This may be an easy error for most of you out there, however, I can't spot it because I'm new to programming. Thanks, M


    #include<stdio.h>
    #include<stdlib.h>
    #include<conio.h>
    //#define MAX 50
    //#define MAX1 5
    float bal=30000;
    char trans_type[50];
    float trans_amount[50];
    char trans_descript[50];
    float cur_bal[50];
    int trans_count=0;
    char type;
    char descript[50];
    float amount;

    void sales(void){
    //printf("\nThis is Sales.\n\n");
    printf("\nEnter transaction amount: ");
    scanf("%f",&amount);
    fflush(stdin);
    printf("\nEnter transaction decription: ");
    gets(descript);
    fflush(stdin);
    type='S';
    bal=bal-amount;
    trans_amount[trans_count]=amount;
    trans_descript[trans_count]=descript; <--here is where it is
    trans_type[trans_count]=type;
    cur_bal[trans_count]=bal;
    trans_count +=1;
    }

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    what are you trying to do at that point in your code?
    trans_descript is a pointer to an array of char. descript is simply a char. i can't tell from your program what your purpose is. either you meant to specifiy a char of the array trans_descript, or you meant descript to contain the string trans_descript points to.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >trans_descript[trans_count]=descript;
    trans_descript is an array of 50 char, descript is an array of 50 char. You're trying to assign an array of 50 char to a single char. To copy descript to trans_descript, use

    strcpy ( trans_descript, descript );

    And include string.h as well.

    float bal=30000;
    char trans_type[50];
    float trans_amount[50];
    char trans_descript[50];
    float cur_bal[50];
    int trans_count=0;
    char type;
    char descript[50];
    float amount;
    Avoid global variables wherever possible.

    >fflush(stdin);
    Using fflush on an input stream results in undefined behavior, don't do it.

    >gets(descript);
    gets is very unsafe, use fgets instead:

    fgets ( descript, sizeof descript, stdin );

    -Prelude
    My best code is written with the delete key.

  4. #4
    Registered User red_baron's Avatar
    Join Date
    May 2002
    Posts
    274
    i think he's trying to take descript's content and give it to trans_descript.
    you can't do that like that, you could do it like this:

    strcpy(trans_descript, descript);
    ¿Red Baron?

    "Imagination is more important than knowledge"
    -Albert Einstein (1879-1955)

    Check out my games!

    [code] /* dont forget code tags! */ [/code]

  5. #5
    Unregistered
    Guest
    Yes that's exactly what I'm attempting to do. I tried this and if then gave me and error ..."Must have Lvalue...." I can't remember exactly but that is the gist of it. I'm basically trying to keep an running history in an inventory program. I used the string.h header file. Is that the correct one? Mark PS. Thanks for trying to help!

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Could you post the most current code you have which displays the error?

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 09:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 12:10 AM

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