Thread: assertion failures

  1. #1

    Post assertion failures

    #include "drinksAtWork.h"

    void main(void)
    drinksAtWork Daw;

    #ifndef DRINKSATWORK_H
    #define DRINKSATWORK_H
    #include <stdlib.h>

    class drinksAtWork
    char *ch;
    void ChooseDrink();


    #include "drinksAtWork.h"
    /*#include <file.h>*/
    #include <iostream.h>
    //#include <fstream.h>

    void drinksAtWork::ChooseDrink()
    cout << ch << endl;
    cout << "Choose your can." << endl;

    /* FILE *fp;//write equivalent code using fstream*/
    cin >> ch;
    ch=new char;

    delete ch;

    at first compiled at linked but when data was entered at the command prompt I ran into an assertion error. I pasted the line of the location of the error in Edit-Breakpoints-Data (Tab)-Enter the expression to be evaluated with the not(!) sign in front of it but it would not be accepted to be evaluated. Now after having closed the compiler and reopened it at another time it has LINK : fatal error LNK1000: unknown error; consult documentation for technical support options. Someone help?

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    ch=new char; 
    It seems here you are allocating space on the free store for a char, and then reallocating the pointer to the start of a string literal - "ff".

    now when you excecute

    cin >> ch;
    You no longer have access to the char you dynamically created.....therefore your proggie is crashing,

    I dont know why you are setting the pointer to the start of "ff".....

    if you set it to a char like so;

    *ch='f'; should work

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File I/O Assertion Failure in VS2008
    By clegs in forum C Programming
    Replies: 5
    Last Post: 12-25-2008, 04:47 AM
  2. Assertion Error
    By tao in forum Windows Programming
    Replies: 7
    Last Post: 06-19-2006, 07:41 AM
  3. Assertion error when looking for window handle
    By axr0284 in forum Windows Programming
    Replies: 3
    Last Post: 02-03-2005, 04:11 PM
  4. Assertion Failure
    By drdroid in forum Windows Programming
    Replies: 22
    Last Post: 01-05-2003, 07:50 PM
  5. Assertion Failure
    By drdroid in forum Game Programming
    Replies: 9
    Last Post: 01-04-2003, 07:02 PM