Thread: Keep getting a bus error

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    7

    Keep getting a bus error

    I'm getting a bus error while running my program, and I pretty sure it's located in this particular function. If anybody can spot what's wrong with it, it would help me out a lot. thanks in advance. (I've left out a lot of the code so you don't have to read through it all)

    Code:
    #include <stdio.h>
    #define NUMPRODUCTS 11
    #define STRINGLEN 50
    
    int main(void)
    {
     
    /*break from code*/
    
            /* step 5: thank user. */
            thankUser(productNames, choice,
    		dollarsBack, quartersBack, dimesBack, nickelsBack, penniesBack);
    }
    
    void thankUser(char productNames[][STRINGLEN], int choice, 
                   int dollarsBack, int quartersBack, int dimesBack, int nickelsBack, int penniesBack) { 
    printf("Thank you for selecting a %s", productNames 
    [choice][STRINGLEN]); printf("Your change is:\n");
    printf("%d dollars\n", dollarsBack);
    printf("%d quarters\n", quartersBack);
    printf("%d dimes\n", dimesBack);
    printf("%d nickels\n", nickelsBack);
    printf("%d pennies\n", penniesBack);
    printf("Enjoy your %s!\n", 
    productNames [choice][STRINGLEN]);

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Code:
    printf("Thank you for selecting a %s", productNames[choice][STRINGLEN]);
    The %s format specifier expects a char*, you are giving it a char. Try dropping the "[STRINGLEN]".

    gg

    [EDIT]
    Same problem on last printf...

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    7
    works now...thanks!!

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. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  5. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM