Help!

This is a discussion on Help! within the C Programming forums, part of the General Programming Boards category; I was working on my program at school and was able to compile it, now i bring it home on ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    49

    Help!

    I was working on my program at school and was able to compile it, now i bring it home on a usb key, try compile it and i get parse error, and filePtr1 undeclared (first use in this function).

    I cant see the error, could someone HELP! The errors are on lines
    FILE *filePtr1;
    filePtr1 = fopen("inputData_temp&speed.txt", "r");

    Code:
    void calc_Reolien(struct DATA *refroidPtr)
    {
          int i = 0, a = 0, w, k = 0, temp2, speed2;
          float Reolien, temp, speed, j;
          
          printf("\nVoici les ou la temperature(s) de refroidissement eolien:\n");
          
          FILE *filePtr1;     
          filePtr1 = fopen("inputData_temp&speed.txt", "r");
          
          do
          {    
               fscanf(filePtr1,"%f", &temp);
               do
               { 
                    
                    if(temp < refroidPtr->temp_airPtr[i])
                         {
                          i += 1;
                         }     
                    else
                         {
                          j = ((float)refroidPtr->temp_airPtr[i] + ((float)refroidPtr->temp_airPtr[i-1])) / 2;
                          if(temp > j)
                               {
                                i = i -1;
                                k += 1;
                               }
                          else
                              {
                               k += 1;
                              }
                         }
                }
                while(k != 1);
                temp2 = i;
                i = 0;
                k = 0;
                
                fscanf(filePtr1, "%f", &speed);
                do
                {   
                    if(speed > refroidPtr->speed_windPtr[i])
                         {
                          i += 1;
                         }     
                    else
                         {
                          j = (refroidPtr->speed_windPtr[i + 1] + (refroidPtr->speed_windPtr[i])) / 2; 
                          if(j <= temp)
                               {
                                i += 1;
                                k += 1;
                               }
                          else
                               {
                                k += 1;
                               }
                         }
                }
                while(k != 1);
                speed2 = i;
                i = 0;
                k = 0;
                
                printf("%d %d", temp2 ,speed2);
                system("PAUSE");
                Reolien = refroidPtr->temp_airPtr[temp2] - refroidPtr->mat_tempspeedPtr[speed2][temp2];
                printf("\n%f",Reolien);
                w = feof(filePtr1);
                printf("%d", w);
          }
          while(w != 0);
          fclose(filePtr1);
          
          free(refroidPtr->temp_airPtr);
          free(refroidPtr->speed_windPtr);
          free(refroidPtr->mat_tempspeedPtr);
    }

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    well you declare the variable, then use it on the next line, so it shouldnt give you an error. my request is to post your complete code. this way we can see the whole picture, and copy/paste to try and compile it on our own machines.

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    49
    ok...

  4. #4
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Can you post the errors please?

    Todd

  5. #5
    Registered User
    Join Date
    Nov 2007
    Posts
    49
    This is the file named refroid.txt that i read from. Here is its content:

    0 -1 -2 -3 -4 -5 -10 -15 -20 -25 -30 -35 -40 -45 -50 -55 -60
    6 8 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100
    2.02 2.17 2.32 2.47 2.62 2.77 3.52 4.27 5.02 5.77 6.51 7.26 8.01 8.76 9.51 10.25 11.00
    2.74 2.91 3.09 3.26 3.44 3.61 4.48 5.36 6.23 7.10 7.97 8.85 9.72 10.59 11.46 12.34 13.21
    3.31 3.51 3.70 3.90 4.09 4.29 5.26 6.23 7.21 8.18 9.15 10.13 11.10 12.07 13.05 14.02 14.99
    4.42 4.65 4.88 5.12 5.35 5.58 6.75 7.91 9.08 10.24 11.41 12.57 13.74 14.90 16.07 17.23 18.40
    5.24 5.50 5.77 6.03 6.29 6.55 7.86 9.17 10.48 11.79 13.10 14.41 15.72 17.02 18.33 19.64 20.95
    5.91 6.19 6.48 6.76 7.05 7.34 8.76 10.19 11.61 13.04 14.46 15.89 17.31 18.74 20.17 21.59 23.02
    6.47 6.78 7.08 7.39 7.69 8.00 9.52 11.04 12.57 14.09 15.62 17.14 18.66 20.19 21.71 23.23 24.76
    6.96 7.28 7.61 7.93 8.25 8.57 10.18 11.79 13.40 15.01 16.62 18.23 19.83 21.44 23.05 24.66 26.27
    7.40 7.73 8.07 8.41 8.74 9.08 10.77 12.45 14.13 15.82 17.50 19.19 20.87 22.56 24.24 25.93 27.61
    7.79 8.14 8.49 8.84 9.19 9.54 11.29 13.04 14.80 16.55 18.30 20.06 21.81 23.56 25.31 27.07 28.82
    8.14 8.50 8.87 9.23 9.59 9.96 11.77 13.59 15.40 17.22 19.03 20.84 22.66 24.47 26.29 28.10 29.92
    8.47 8.84 9.22 9.59 9.97 10.34 12.21 14.08 15.96 17.83 19.70 21.57 23.44 25.31 27.19 29.06 30.93
    8.77 9.16 9.54 9.93 10.31 10.70 12.62 14.54 16.47 18.39 20.32 22.24 24.17 26.09 28.02 29.94 31.86
    9.05 9.45 9.84 10.24 10.63 11.03 13.00 14.97 16.95 18.92 20.90 22.87 24.84 26.82 28.79 30.76 32.74
    9.32 9.72 10.13 10.53 10.93 11.34 13.36 15.38 17.40 19.42 21.44 23.46 25.48 27.50 29.52 31.54 33.55
    9.57 9.98 10.39 10.80 11.22 11.63 13.69 15.76 17.82 19.88 21.95 24.01 26.07 28.14 30.20 32.26 34.33
    9.80 10.22 10.64 11.06 11.49 11.91 14.01 16.11 18.22 20.32 22.43 24.53 26.64 28.74 30.84 32.95 35.05
    10.03 10.45 10.88 11.31 11.74 12.17 14.31 16.46 18.60 20.74 22.88 25.03 27.17 29.31 31.46 33.60 35.74
    10.24 10.67 11.11 11.55 11.98 12.42 14.60 16.78 18.96 21.14 23.32 25.50 27.68 29.86 32.04 34.22 36.40
    10.44 10.88 11.33 11.77 12.21 12.66 14.87 17.09 19.30 21.52 23.74 25.95 28.17 30.38 32.60 34.81 37.03
    10.64 11.09 11.54 11.99 12.43 12.88 15.13 17.38 19.63 21.88 24.13 26.38 28.63 30.88 33.13 35.38 37.63




    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    struct DATA
    {
           int num_columns;
           int num_rows;
           int *temp_airPtr;
           int *speed_windPtr;
           float **mat_tempspeedPtr;
    };
    
    int fill_struct_integers(struct DATA *);
    int fill_struct_arrays(struct DATA *);
    int input_data(struct DATA *);
    float validate_input_temp(int, struct DATA *);
    float validate_input_speed(int, struct DATA *);
    void calc_Reolien(struct DATA *);
    
    int main()
    {
          int x, compteur;
          struct DATA REFROID;
                  
          x = fill_struct_integers(&REFROID);                                      
          if(x == 0)
               {
               system("PAUSE");
               return 0;
               }
          
          x = fill_struct_arrays(&REFROID);
          if(x == 0)
               {
               system("PAUSE");
               return 0;
               }
          
          compteur = input_data(&REFROID);
          if(compteur == 0)
               {
                system("PAUSE");
                return 0;
               }
               
          calc_Reolien(&REFROID);
          
                                                                                                          
          system("PAUSE");
          return 0;
    }
    
    int fill_struct_integers(struct DATA *refroidPtr)
    {
          int i, x, y, numchar = 0, row = 3;
          float w;
          char c;
          
          FILE *filePtr;
          filePtr = fopen("refroid.txt","r");
          if(filePtr == NULL)
               {
               printf("Erreur en ouvrant le fichier. Referer vous au guide d'utilisation pour plus d'information.\n");
               system("PAUSE");
               return 0;
               }
           
          do
          {
               x = fscanf(filePtr,"%d", &y);           
               
               if(x == 0)
                    {
                    numchar += 1;  
                    if(numchar == 1)
                         {
                         printf("La %dere donnee de la premiere ligne dans le fichier refroid.txt est corompu.\n", numchar);
                         }
                    else
                         {
                         printf("La %de donnee de la premiere ligne dans le fichier refroid.txt est corompu.\n", numchar);
                         }
               
                    return 0;
                    }
               
               if(x == -1 && numchar == 0)
                    {
                    printf("Le fichier refroid.txt est vide.\n");
                    return 0;
                    }
                    
               fscanf(filePtr,"%c", &c);
               numchar += 1;
          }
          while(c != '\n' && x != -1);
          refroidPtr->num_columns = numchar;
          
          numchar = 0;
          do
          {
               x = fscanf(filePtr,"%d", &y);
               
               if(x == 0)
                    {
                    numchar += 1;  
                    if(numchar == 1)
                         {
                         printf("La %dere donnee de la deuxieme ligne dans le fichier refroid.txt est corompu.\n", numchar);
                         }
                    else
                         {
                         printf("La %de donnee de la deuxieme ligne dans le fichier refroid.txt est corompu.\n", numchar);
                         }
               
                    return 0;
                    }
          
               if(x == -1 && numchar == 0)
                    {
                    printf("Le fichier refroid.txt ne contient qu'une ligne.\n");
                    return 0;
                    }
          
               fscanf(filePtr,"%c", &c);
               numchar += 1;
          }
          while(c != '\n' && x != -1);
          refroidPtr->num_rows = numchar;
          
          if(x == -1)
               {
               printf("Le fichier refroid.txt ne contient pas de %de ligne.\n", row); 
               return 0;
               }
          
          row = 2;
          for(i = 0; i < refroidPtr->num_rows; i++)
          {
               row += 1;
               numchar = 0;
               do
               {
                    x = fscanf(filePtr,"%f", &w);
                    
                    if(x == 0)
                         {
                         numchar += 1;  
                         
                         if(numchar == 1)
                              {
                              printf("La %dere donnee de la %de ligne dans le fichier refroid.txt est corompu.\n", numchar, row);
                              }
                         else
                              {
                              printf("La %de donnee de la %de ligne dans le fichier refroid.txt est corompu.\n", numchar, row);
                              }
                         
                         return 0;
                         }
                        
                    
                    fscanf(filePtr,"%c", &c);
                    numchar += 1;
                    y = feof(filePtr);
                    
               }
               while( c != '\n' && y <= 0);
    
               if(numchar == 1 && x == -1)
                    {
                     if(0 != refroidPtr->num_rows - (row - 2))
                          {
                          y = refroidPtr->num_rows - (row - 2);
                          printf("Le fichier refroid.txt ne contient pas de %de ligne, ou bien il y a %d element de trop dans la 2e ligne.\n", row, y);
                          return 0;
                          }
                    } 
               
               if(numchar < refroidPtr->num_columns && x != -1)
                    {
                    y = refroidPtr->num_columns - numchar;
                    printf("Soit que la %de ligne du fichier refroid.txt est %d elements de courts, ou bien que la premiere ligne en a %d de trop.\n", row, y, y);
                    return 0;
                    }
                    
               if(numchar > refroidPtr->num_columns)
                    {
                    y = numchar - refroidPtr->num_columns;
                    printf("Soit que la %de ligne du fichier refroid.txt est %d elements de trop, ou bien que la premiere ligne en manque %d.\n", row, y, y);
                    return 0;
                    }
          }
          fclose(filePtr);      
          
          return 1;
    }
    
    int fill_struct_arrays(struct DATA *refroidPtr)
    {
          int i, j, y, numchar = 0;
          char c;
          float z;
          
          FILE *filePtr;
          filePtr = fopen("refroid.txt","r");
          if(filePtr == NULL)
               {
               printf("Erreur en ouvrant le fichier. Referer vous au guide d'utilisation pour plus d'information.\n");
               system("PAUSE");
               return 0;
               }
          
          refroidPtr->temp_airPtr = (int *) calloc(refroidPtr->num_columns, sizeof (int));     
          i = 0;
                do
                {
                     fscanf(filePtr,"%d", &refroidPtr->temp_airPtr[i]);     
                     fscanf(filePtr,"%c", &c);
                     i += 1;
                }
                while(c != '\n');
             
         refroidPtr->speed_windPtr = (int *) calloc(refroidPtr->num_rows, sizeof (int));
         i = 0;
                do
                {
                     fscanf(filePtr,"%d", &refroidPtr->speed_windPtr[i]);
                     fscanf(filePtr,"%c", &c);
                     i += 1;
                }
                while(c != '\n');
          
          refroidPtr->mat_tempspeedPtr = (float **) calloc(refroidPtr->num_rows, sizeof (float *));
          for(i = 0; i < refroidPtr->num_rows; i++)
               {
               refroidPtr->mat_tempspeedPtr[i] = (float *) calloc(refroidPtr->num_columns, sizeof (float));
               }
          
          for(i = 0; i < refroidPtr->num_rows; i++)
               {
                j = 0;
                      do
                      {
                           fscanf(filePtr, "%f", &refroidPtr->mat_tempspeedPtr[i][j]);
                           fscanf(filePtr,"%c", &c);
                           j += 1;
                           y = feof(filePtr);
                      }
                      while( c != '\n' && y <= 0);
                      
               }
          
         return 1; 
    }
    
    int input_data(struct DATA *refroidPtr)
    {
         int compteur = 0;
         double x;
         FILE *filePtr1;     
         filePtr1 = fopen("inputData_temp&speed.txt", "w");
         
         printf("Entrez la temperature de l'air ainsi que la vitesse du vent.\nPour indiquer la fin d'entrée, entrez le -1.\n");
         do
         {
              x = 0;
              printf("\n(Temperature)=> ");
              x = validate_input_temp(0, refroidPtr);
              
              if(x != 999)
                   {
                   fprintf(filePtr1, "%f\n", x);
                   }
              
              if(x != 999)
              {
                   printf("(vitesse)=> ");
                   x = validate_input_speed(0, refroidPtr);
                   if(x != 999)
                        {
                        fprintf(filePtr1, "%f\n", x);
                        compteur += 1;
                        }
              }
         }while(x != 999);
         fclose(filePtr1);  
         return compteur;
    }
    
    float validate_input_temp(int disperror, struct DATA *refroidPtr)
    {
     //Déclarations de variables.
          float choice;
          int numchar = 0;
          char c;
    
          //Si disperror est égale à 1, un message d'erreur est imprimé.
          if(disperror == 1)
                 {
                       printf("\nErreur, valeur endehors des bornes permises. Entrez une nouvelle valeur.\n=>");
                 }
    
          //La valeur entrée par l'utilisateur est affecté à la variable choice.
          scanf("%f", &choice);
          if(choice == 999)
               {
                return 999.0;
               }
          //Tant et aussi longtemps que c n'est pas ègale à une nouvelle ligne, numchar est incrémenter de 1.
          do 
          {
          scanf("%c", &c);
          numchar += 1 ;
          } while(c != '\n');
          
           
          //Si numchar n'égale pas 1, la fonction est appelée avec un paramètre de disperror égale à 1.
          if(numchar != 1)
                 {
                       choice = validate_input_temp(1, refroidPtr);
                 }
           
          //Si choice es plus petit ou égale à 0, la fonction est appelée avec un paramètre de disperror égale à 1.
          if(choice > refroidPtr->temp_airPtr[0] || choice < refroidPtr->temp_airPtr[(refroidPtr->num_columns)-1])
                 {
                       choice = validate_input_temp(1, refroidPtr);
                 }
           
          return choice;
    }
    
    float validate_input_speed(int disperror, struct DATA *refroidPtr)
    {
     //Déclarations de variables.
          float choice;
          int numchar = 0;
          char c;
    
          //Si disperror est égale à 1, un message d'erreur est imprimé.
          if(disperror == 1)
                 {
                       printf("\nErreur, valeur endehors des bornes permises. Entrez une nouvelle valeur.\n=>");
                 }
    
          //La valeur entrée par l'utilisateur est affecté à la variable choice.
          scanf("%f", &choice);
    
          if(choice == 999)
               {
                return 999.0;
               }
          
          //Tant et aussi longtemps que c n'est pas ègale à une nouvelle ligne, numchar est incrémenter de 1.
          do 
          {
          scanf("%c", &c);
          numchar += 1 ;
          } while(c != '\n');
          printf("%c", c);
          
          //Si numchar n'égale pas 1, la fonction est appelée avec un paramètre de disperror égale à 1.
          if(numchar != 1)
                 {
                       choice = validate_input_speed(1, refroidPtr);
                 }
          
          //Si choice es plus petit ou égale à 0, la fonction est appelée avec un paramètre de disperror égale à 1.
          if(choice < refroidPtr->speed_windPtr[0] || choice > refroidPtr->speed_windPtr[(refroidPtr->num_rows)-1])
                 {
                       choice = validate_input_speed(1, refroidPtr);
                 }
    
          return choice;
    }
    
    void calc_Reolien(struct DATA *refroidPtr)
    {
          int i = 0, a = 0, w, k = 0, temp2, speed2;
          float Reolien, temp, speed, j;
          
          printf("\nVoici les ou la temperature(s) de refroidissement eolien:\n");
          
          FILE *filePtr1;     
          filePtr1 = fopen("inputData_temp&speed.txt", "r");
          
          do
          {    
               fscanf(filePtr1,"%f", &temp);
               do
               { 
                    
                    if(temp < refroidPtr->temp_airPtr[i])
                         {
                          i += 1;
                         }     
                    else
                         {
                          j = ((float)refroidPtr->temp_airPtr[i] + ((float)refroidPtr->temp_airPtr[i-1])) / 2;
                          if(temp > j)
                               {
                                i = i -1;
                                k += 1;
                               }
                          else
                              {
                               k += 1;
                              }
                         }
                }
                while(k != 1);
                temp2 = i;
                i = 0;
                k = 0;
                
                fscanf(filePtr1, "%f", &speed);
                do
                {   
                    if(speed > refroidPtr->speed_windPtr[i])
                         {
                          i += 1;
                         }     
                    else
                         {
                          j = (refroidPtr->speed_windPtr[i + 1] + (refroidPtr->speed_windPtr[i])) / 2; 
                          if(j <= temp)
                               {
                                i += 1;
                                k += 1;
                               }
                          else
                               {
                                k += 1;
                               }
                         }
                }
                while(k != 1);
                speed2 = i;
                i = 0;
                k = 0;
                
                printf("%d %d", temp2 ,speed2);
                system("PAUSE");
                Reolien = refroidPtr->temp_airPtr[temp2] - refroidPtr->mat_tempspeedPtr[speed2][temp2];
                printf("\n%f",Reolien);
                w = feof(filePtr1);
                printf("%d", w);
          }
          while(w != 0);
          fclose(filePtr1);
          
          free(refroidPtr->temp_airPtr);
          free(refroidPtr->speed_windPtr);
          free(refroidPtr->mat_tempspeedPtr);
    }

  6. #6
    Registered User
    Join Date
    Nov 2007
    Posts
    49
    here are the errors

    385 c:\docume~1\andre\mydocu~1\lcc\lab4\refroid\lab4.c
    parse error before `*'

    386 c:\docume~1\andre\mydocu~1\lcc\lab4\refroid\lab4.c
    `filePtr1' undeclared (first use in this function)

    386 c:\docume~1\andre\mydocu~1\lcc\lab4\refroid\lab4.c
    (Each undeclared identifier is reported only once

    386 c:\docume~1\andre\mydocu~1\lcc\lab4\refroid\lab4.c
    for each function it appears in.)

  7. #7
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    compiles fine for me on with dev-cpp (gcc compiler). what compiler and command (if any) are you using?

    edit: make sure the file is saved and your trying to compile the file you have posted here.
    Last edited by nadroj; 12-03-2007 at 06:32 PM.

  8. #8
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    I do not get those errors. I get 3 warnings for unused variables is all. (y, numchar and a)

    Todd

  9. #9
    Registered User
    Join Date
    Nov 2007
    Posts
    49
    Im using dev-c++ 4.01

    How can I tell wich compiler im using?

  10. #10
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    if your using dev-cpp, it should have gcc (if you downloaded dev-cpp with compiler, not just the ide). from a command line try 'gcc -v'. my version of dev-cpp is 4.9.9.2 which came with gcc 3.4.2.

  11. #11
    Registered User
    Join Date
    Nov 2007
    Posts
    49
    Ok, my brother took the printf line and put it in beetween the File and fileptr = ... lines and now it works....?????

  12. #12
    Registered User
    Join Date
    Nov 2007
    Posts
    49
    Ty for the help...

  13. #13
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    Code:
          printf("\nVoici les ou la temperature(s) de refroidissement eolien:\n");
          
          FILE *filePtr1;     
          filePtr1 = fopen("inputData_temp&speed.txt", "r");
    whether the printf is before the FILE, after the FILE, or after the fopen lines shouldnt make a difference.

  14. #14
    Registered User
    Join Date
    Nov 2007
    Posts
    49
    I dont see wher i dont use the variable y.

  15. #15
    Registered User
    Join Date
    Nov 2007
    Posts
    49
    Quote Originally Posted by nadroj View Post
    Code:
          printf("\nVoici les ou la temperature(s) de refroidissement eolien:\n");
          
          FILE *filePtr1;     
          filePtr1 = fopen("inputData_temp&speed.txt", "r");
    whether the printf is before the FILE, after the FILE, or after the fopen lines shouldnt make a difference.
    I know

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

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