I'm having problems declaring arrays in my .h file for my .c file.
upon compiling in linux using gcc i get:
Whats wrong? I need an answer today please, as it's due tommorow. I've pretty much completed my program, its just this (and another minor thing) that are bugging me!Code:In file included from src/n5441137.c:9: include/component.h:27: `f' undeclared here (not in a function) include/component.h:27: initializer element is not constant include/component.h:27: (near initialization for `EMultipliers[0]') include/component.h:27: `p' undeclared here (not in a function) include/component.h:27: initializer element is not constant include/component.h:27: (near initialization for `EMultipliers[1]') include/component.h:27: `n' undeclared here (not in a function) include/component.h:27: initializer element is not constant include/component.h:27: (near initialization for `EMultipliers[2]') include/component.h:27: `u' undeclared here (not in a function) include/component.h:27: initializer element is not constant include/component.h:27: (near initialization for `EMultipliers[3]') include/component.h:27: `m' undeclared here (not in a function) include/component.h:27: initializer element is not constant include/component.h:27: (near initialization for `EMultipliers[4]') include/component.h:27: `k' undeclared here (not in a function) include/component.h:27: initializer element is not constant include/component.h:27: (near initialization for `EMultipliers[5]') include/component.h:27: `M' undeclared here (not in a function) include/component.h:27: initializer element is not constant include/component.h:27: (near initialization for `EMultipliers[6]') include/component.h:27: `G' undeclared here (not in a function) include/component.h:27: initializer element is not constant
Here are the arrays ive written:
Code:/*arrays for comparing standard values, input of RLC */ /*Engineering Multipliers*/ char EMultipliers[8]={f,p,n,u,m,k,M,G}; int EMPowers[8] = {-15,-12,-9,-6,-3,3,6,9}; /* Resistors: decade multiples for 10, 100, 1000, 10000, 100000, 1000000 ohms- */ const float StRes[24]={10,11,12,13,14,16,18,20,22,24,27,30,33,36,39,43,47,51,56,62,68,75,82,91}; /* Inductor: for multiples of 1, 10, 100, 1000 for nH, uH values*/ const float StInd[25]={1.0,1.1,1.2,1.3,1.5,1.6,1.8,2.0,2.2,2.4,2.7,3.0,3.3,3.6,3.9,4.3,4.7,5.1,5.6,6.2,6.8,7.5,8.2,8.7,9.1}; /* Capacitor: for pF values, multiples of 1,10,100,1000; note :for uF values, multiples of 1/100,1/10,1,10,100,1000, for elem 1,5, 9,13,17,21 also 10000 for element 1*/ const float StCap[25]={1.0,1.1,1.2,1.3,1.5,1.6,1.8,2.0,2.2,2.4,2.7,3.0,3.3,3.6,3.9,4.3,4.3,4.7,5.1,5.6,6.2,6.8,7.5,8.2,9.1};
and where they are used in my .c file:
cheersCode:float FormatIn(char *instr) { /*converts eng multiplier at end of string*/ int length =0; int i =0; char *tmpstr1=NULL; char *tmpstr2=NULL; char *power = NULL; char *final = NULL; char lastchar; int multi; length=strlen(instr); /*find eng char*/ if (sscanf(instr,"%[^fpnumkMG]s",tmpstr1)>0){ lastchar = *instr; } /* check type*/ for(i=0;i<9;i++) { if (lastchar == EMultipliers[i]){ multi = EMPowers[i]; } } /*print the power with an e in front*/ sprintf(power,"e%i", multi); /*makes the number as a string*/ if (strcat(tmpstr1, power) != NULL); { sprintf(final,"%s",tmpstr1); } return atof(final); } float StdIn(float inValStr, char typechar) { /* input must be in full float format!*/ float result =0; float val=0; float first; float second; int i=0; float m=1; float multiple = 1; val = inValStr; /*for individual type of RLC compare value to std's*/ switch(typechar) { case 'R': for(m=1;m<=1000000;m=m*10) { /*get lowest multiple*/ if ((val/m) < 1) { multiple = m/10; } } for (i=0;i<25;i++) { /* now compare to standard values*/ first = StRes[i]*multiple - val; second = StRes[i+1]*multiple - val; if (first < second) { result = StRes[i]; } else { result = StRes[i+1]; } } break; case 'L': for(m=1;m<=1000;m=m*10) { /*get lowest multiple*/ if ((val/m) < 1) { multiple = m/10; } } for (i=0;i<26;i++) { /* now compare to standard values*/ first = StInd[i]*multiple - val; second = StInd[i+1]*multiple - val; if (first < second) { result = StInd[i]; } else { result = StInd[i+1]; } } break; case 'C': for(m=1;m<=1000000;m=m*10) { /*get lowest multiple*/ if ((val/m) < 1) { multiple = m/10; } } for (i=0;i<26;i++) { /* now compare to standard values*/ first = StCap[i]*multiple - val; second = StCap[i+1]*multiple - val; if (first < second) { result = StCap[i]; } else { result = StCap[i+1]; } } break; default:break; } return result; }