c - Assistance needed with pointers and arrays -


ok, writing program reads input file , puts them arrays. trying use pointers arrays can point spot in array , add user defined float float exists.

this code far:

    #include <stdio.h>     #include <stdlib.h>     #include <string.h>      int menu1();      int main()     {         file * ifp = fopen("input2.txt","r"); //open input file         int cars = 5, , j, k; // initialized cars , counters i, j, , k         char *view="view", *bid="bid", *close="close", choice1[20]; //initialize character arrays         float start_bid[5]={0.00}, min_bid[5]={0.00}, cur_bid[5]={0.00}, usr_bid[5]=0.00};          int comparelimit = 100, selection=0;          //scan file , appropriate numbers respective arrays         (i = 0; < cars; i++)             {                 fscanf(ifp, "%f %f", &start_bid[i],&min_bid[i]);             }           printf("welcome silent auction\n\n");         menu1(); //display menu         scanf("%s", &choice1); //            int result = strncmp(choice1, view, comparelimit); //compare 2 strings         if(result == 0)         {             selection = selection + 1;          }           int result2 = strncmp(choice1, bid, comparelimit); //compare 2 strings         if(result2 == 0)         {             selection = selection + 2;          }          int result3 = strncmp(choice1, close, comparelimit); //compare 2 strings         if(result3 == 0)         {             selection = selection + 3;         }           while (selection < 3)     {             if (selection == 1)             {                 printf("number\tcurrent bid\tminimum increase\n");                 printf("1\t$%.2f\t\t$%.2f\n",cur_bid[0], min_bid[0]);                 printf("2\t$%.2f\t\t$%.2f\n",cur_bid[1], min_bid[1]);                 printf("3\t$%.2f\t\t$%.2f\n",cur_bid[2], min_bid[2]);                 printf("4\t$%.2f\t\t$%.2f\n",cur_bid[3], min_bid[3]);                 printf("5\t$%.2f\t\t$%.2f\n",cur_bid[4], min_bid[4]);                  menu1();                 scanf("%s", &choice1);             }               else if (selection == 2)             {                 int k;                 float usr_bid;                  printf("which auction bid on? (1-5)\n");                 scanf("%d", k);                  if (cur_bid[k - 1] = 0.00)                     min_bid[k - 1] = start_bid[k - 1];                 else                     min_bid[k - 1] = cur_bid[k - 1] + min_bid[k - 1];                  printf("the minimum bid %.2f\n", min_bid[k - 1]);                 printf("how bid?\n");                 scanf("%f", usr_bid);                  if (usr_bid < min_bid[k-1])                     printf("sorry, bid not high enough.\n");                 else                     cur_bid[k - 1] = usr_bid + cur_bid[k - 1];                  menu1();                 scanf("%s", &choice1);             }              else             {                int i;                int auction = 1;                 (i=0; < cars; i++)                {                     (auction = 1; auction < cars; auction++)                     {                         while (cur_bid[i]!= 0.00)                             printf("auction %d sold $%.2f", auction, cur_bid);                      }                }             }     }                fclose(ifp);            return 0;     }       int menu1()     {         printf("please make selection (in caps):\n");         printf("\tview auctions [view]\n");         printf("\tbid on auction [bid]\n");         printf("\tclose auctions [close]\n");      } 

my program works while loop else if (selection == 2) is. asks me auction want. , when give number, freezes, crashes, , doesn't give me errors other process terminated status -1073741510.

any ideas?

the pointers pass scanf() incorrect.

change:

   scanf("%d", k); 

to

   scanf("%d", &k); 

and change:

scanf("%s", &choice1); //  

to

 scanf("%s", choice1); //  

in 2 places.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -