Memory cannot be read error?

This is a discussion on Memory cannot be read error? within the C Programming forums, part of the General Programming Boards category; Hello, i am getting application errors while running this code. It happens on the line in my code where i ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    3

    Question Memory cannot be read error?

    Hello, i am getting application errors while running this code. It happens on the line in my code where i marked with >>>. No errors appear in compiler. What have I done wrong. Thanks...


    --------------------------------------------------------------------------------
    #include<stdio.h>
    #define Z 10

    void main(void)
    {
    char produce[10][15]={"Bologna","Franks","Salami","Pepperoni","Bagett" ,"Bread","Cole Slaw","Potato Salad","Tuna Salad","Fruit Salad"}, *Prod;
    double price[10]={2.29, 1.99, 4.99, 3.99, 0.99, 1.29, 1.35, 2.09, 3.05, 2.78};
    int i, weight;
    double line[10];
    double prodTot=0;
    char yORn;

    for(i=1;i<=Z;++i)
    {
    printf("%2i %-13s $%g/lbs\n",i, produce[i-1], price[i-1]);
    }
    do
    {
    printf("\nEnter the number of the item you want: ");
    >>>scanf ("%i", &i);
    fflush(stdin);
    Prod = produce[i-1];
    printf("\n\nHow many pounds of %s would you like?", Prod[i-1]);
    scanf ("%i", &weight);
    fflush(stdin);
    prodTot = weight * price[i-1];
    printf("\n%i lbs of %s is $%g\n",weight,Prod,prodTot);
    printf("\nNeed anything else?");
    scanf ("%c", &yORn);
    fflush(stdin);


    }while (yORn == 'y' || yORn == 'Y');

    }
    ----------------------------------------------------------------------------------

  2. #2
    Unregistered
    Guest
    use "%d" for integers instead of "%i".....?

  3. #3
    Registered User alex's Avatar
    Join Date
    Sep 2001
    Posts
    132
    Nope, it's not the scanf...

    In the printf statement, you should use "Prod", not "Prod[i-1]".

    By the way: way the fflushes?

    You'll see that you need an extra space in the last scanf format string: " %c" instead of "%c" to let the program function correctly.

    greetinx,
    alex

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    3

    Talking thanks alex

    that was the problem...thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 02:17 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 09:11 AM
  4. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 11:52 PM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM

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