Thread: Pointer and If Statement

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2014
    Posts
    9

    Pointer and If Statement

    Hello,

    I am trying to use an if statement which has a pointer in it to determine which function to use.

    The original code would be -

    Code:
    pqueue *pq = new_bounded_pqueue(5,le_artist);
    I want to use an if statement so if a user inputs a certain variable it will declare a different line of code. Here is what I have done so far -

    Code:
    printf("Please enter if you want to order by ascending or descending, A = Assending, D = Descending:   \n");    scanf("%c", &order);
        
        pqueue *pq;
    
    
        if (order == 'A' || order == 'a')    {
        pqueue *pq = new_bounded_pqueue(5,le_artist);
        }
        else if (order == 'D' || order == 'd')
        {
        pqueue *pq = new_bounded_pqueue(5,le_artistdec);
        }

    Once compiled the program runs but as soon as I input data I return a segmentation fault.
    Last edited by Nathan Kent; 12-22-2014 at 05:05 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Statement inside a statement.
    By JOZZY& Wakko in forum C Programming
    Replies: 15
    Last Post: 11-05-2009, 03:18 PM
  2. Replies: 3
    Last Post: 10-30-2009, 04:41 PM
  3. Replies: 4
    Last Post: 08-27-2007, 11:51 PM
  4. Pointer syntax in if statement
    By fkheng in forum C Programming
    Replies: 5
    Last Post: 06-10-2003, 04:01 AM
  5. Replies: 2
    Last Post: 08-05-2002, 04:52 PM