Help!

This is a discussion on Help! within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> #include <stdlib.h> #include <math.h> int main() { FILE *infile; float skatertime[32][1500]; int i, a, b; float left, ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    1

    Exclamation Help!

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    int main()
    {
      FILE *infile;
      float skatertime[32][1500];
      int i, a, b;
      float left, right, add;
    
      infile = fopen("speed", "r");
      if (infile == NULL)
        {
          printf("speed not working\n");
          exit(1);
        }
    
      for (i = 0; i < 12; i++)
        {
          fscanf(infile, "%f %f", &skatertime[a], &skatertime[b]);
          printf("Left: %f	Right %f\n", skatertime[a], skatertime[b]);
          a++;
          b++;
        }
    
      return 0;
    }

    i keep getting these errors


    dsu@Ubuntu9:~/programs$ gcc todayfile1.c -o todayfile1
    todayfile1.c: In function ‘main’:
    todayfile1.c:21: warning: format ‘%f’ expects type ‘float *’, but argument 3 has type ‘float (*)[1500]’
    todayfile1.c:21: warning: format ‘%f’ expects type ‘float *’, but argument 4 has type ‘float (*)[1500]’
    todayfile1.c:22: warning: format ‘%f’ expects type ‘double’, but argument 2 has type ‘float *’
    todayfile1.c:22: warning: format ‘%f’ expects type ‘double’, but argument 3 has type ‘float *’

  2. #2
    Registered User
    Join Date
    Feb 2010
    Posts
    37
    can u tell me in the speed file what content you are having

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    In this line of code:
    Code:
    fscanf(infile, "%f %f", &skatertime[a], &skatertime[b]);
    You need to specify the second index. Without it, you have an address to an array of 1500 elements.

    Before the for loop starts, you want to initialize a and b.
    Last edited by Adak; 02-22-2010 at 09:27 PM.

  4. #4
    Registered User
    Join Date
    Feb 2010
    Posts
    57
    If you faced that warning in only compile time it is not a problem with the content of speed file.
    I think you faced in the compile time only. So it is a problem with your gcc.

    I am working this program in Linux environment I didn't faced any problem.

    If you are not declared a a and b variable also it will take some garbage value and it will process based on that. you can try with new installed gcc compiler. If you faced same problem inform again.

Popular pages Recent additions subscribe to a feed

Tags for this Thread


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