Header File Arrays

This is a discussion on Header File Arrays within the C Programming forums, part of the General Programming Boards category; I'm having problems declaring arrays in my .h file for my .c file. upon compiling in linux using gcc i ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    6

    Question Header File Arrays

    I'm having problems declaring arrays in my .h file for my .c file.

    upon compiling in linux using gcc i get:

    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
    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!


    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:

    Code:
    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;
    }
    cheers

  2. #2
    Registered User
    Join Date
    Sep 2005
    Posts
    5
    doesnt a char[] need to be declared like this:
    Code:
    char[] = {'f','p','n','u','m','k','M','G'};
    Ochams Razor (sp?) may not be right this time however?

    Joel

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    6
    excellent.

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    also
    Code:
    char EMultipliers[] = "fpnumkMG";

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 05:27 PM
  2. Need help understanding Header Files
    By Kaidao in forum C++ Programming
    Replies: 11
    Last Post: 03-25-2008, 11:02 AM
  3. Class methods in header or source file?
    By TriKri in forum C++ Programming
    Replies: 13
    Last Post: 09-17-2007, 06:23 AM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 04:39 AM
  5. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM

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