char compile error

This is a discussion on char compile error within the C Programming forums, part of the General Programming Boards category; Hi, I am new to c programming and this is my first post here. Code: char user_file[20]; //copy the unique ...

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    5

    char compile error

    Hi, I am new to c programming and this is my first post here.

    Code:
    char user_file[20];
    //copy the unique name into the new array
    
    user_file[0] = li1;
    
    user_file[1] = li2;
    
    user_file[2] = li3;
    
    user_file[3] = li4;
    
    user_file[4] = li5;
    
    
    
    // now add what ever other filename identification you like
    
    user_file[5] = '.';
    
    if(user_time==60){
    
      user_file[6] = 'o';
    
      user_file[7] = 'n';
    
      user_file[8] = 'e';
    
    }
    
    else if(user_time==300){
    
      user_file[6] = 'f';
    
      user_file[7] = 'i';
    
      user_file[8] = 'v';
    
    }
    
    else if(user_time==600){
    
      user_file[6] = 't';
    
      user_file[7] = 'e';
    
      user_file[8] = 'n';
    
    }
    
    //null terminate the string
    
    user_file[9] = '\0';
    produces this compile error

    Code:
    login.c: In function ‘login’:
    login.c:294: error: subscripted value is neither array nor pointer
    login.c:295: error: subscripted value is neither array nor pointer
    login.c:296: error: subscripted value is neither array nor pointer
    login.c:297: error: subscripted value is neither array nor pointer
    login.c:298: error: subscripted value is neither array nor pointer
    login.c:301: error: subscripted value is neither array nor pointer
    login.c:303: error: subscripted value is neither array nor pointer
    login.c:304: error: subscripted value is neither array nor pointer
    login.c:305: error: subscripted value is neither array nor pointer
    login.c:308: error: subscripted value is neither array nor pointer
    login.c:309: error: subscripted value is neither array nor pointer
    login.c:310: error: subscripted value is neither array nor pointer
    login.c:313: error: subscripted value is neither array nor pointer
    login.c:314: error: subscripted value is neither array nor pointer
    login.c:315: error: subscripted value is neither array nor pointer
    login.c:318: error: subscripted value is neither array nor pointer
    I doubt that this makes any difference but I am compiling with AVR-GCC. I am at a loss so any help will be appreciated.

  2. #2
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738
    Is the code you posted part of the said "login" function that is displayed in the error? Is that the function in its entirety?
    My Website

    "Circular logic is good because it is."

  3. #3
    Registered User
    Join Date
    Jun 2009
    Posts
    5
    This is not the entire function but only a portion of it

  4. #4
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Please post the entire function(s) where you are modifying user_file. It's important to see where that variable is declared, defined and modified.

  5. #5
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738
    The code you have posted has no errors in it (as long as variables li1 through li5 and user_time are defined correctly outside of the code you posted). I compiled a subset of what you posted, and it compiled fine:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main (void)
    {
    	int user_time = 60;
    	char user_file[20];
    	
    	user_file[5] = '.';
    
    	if(user_time==60){
    	  user_file[6] = 'o';
    	  user_file[7] = 'n';
    	  user_file[8] = 'e';
    	}
    
    	//null terminate the string
    	user_file[9] = '\0';
    	
    	return 0;
    }
    Your problem lies elsewhere. Can you post a different portion of the function that is more probable to contain the error?
    My Website

    "Circular logic is good because it is."

  6. #6
    Registered User
    Join Date
    Jun 2009
    Posts
    5
    This bit of code is declared globally at the top of main
    Code:
    char user_file[20];
    Other than this, user_file is not found anywhere in main. Main then calls login directly.

    This is the entire login funciton
    Code:
    //login.c
    
    //state==1
    
    
    #include "system.h"
    #include <stdlib.h>
    
    #include <avr/pgmspace.h>
    
    
    
    //declare variables
    
    //extern unsigned char ticks;
    
    extern volatile unsigned char screen;
    
    extern volatile unsigned char state;
    
    extern unsigned char last_btn_clicked; //variable returned by interrupt buttons
    
    extern unsigned char last_btn_clicked_held;
    
    extern unsigned char loggedin;
    
    extern unsigned char user_time;
    
    extern unsigned char dpError;
    
    extern char user_file;
    
    
    
    
    
    void login(void){
    
    	//define local variables
    
    	//login values
    
    	signed char  li1=1;
    
    	signed char  li2=2;
    
    	signed char  li3=3;
    
    	signed char  li4=4;
    
    	signed char  li5=5;
    
    	signed char  li6=0;
    
    	signed char  li7=9;
    
    	signed char  li8=2;
    
    	signed char  li9=1;
    
    	signed char  li10=0;
    
    	signed char  li11=1;
    
    	signed char  li12=8;
    
    	signed char  li13=0;
    
    	//validation values
    
    	signed char  vi1=0;
    
    	signed char  vi2=0;
    
    	signed char  vi3=0;
    
    	signed char  vi4=0;
    
    	signed char  vi5=0;
    
    	signed char  vi6=0;
    
    	signed char  vi7=0;
    
    	signed char  vi8=0;
    
    
    
    	unsigned int  cutterNo;
    
    
    	char loop=1;
    
    	unsigned int parseA;
    
    	unsigned int parseB;
    
    	long login_code;
    
    	char pass;
    
    
    
    
    
    	//get the cutterNo number
    
    	cutterNo=1234;
    
    	
    
    	while(loop){
    
    		input();
    
    		//*********************** Login
    
    		LCDdisplay(0,0,"Login:");
    
    		if(screen>=13){
    
    			LCDdisplay(0,1,"                    ");
    
    			LCDdisplay(0,2,"                    ");
    
    		}
    
    		else{
    
    			LCDdisplay(0,2,"Left & Right to Set");
    
    			LCDdisplay(0,3,"Accept to Continue");
    
    		}
    
    		
    
    
    
    		//************************************************************
    
    		//                                            Enter set one
    
    		//************************************************************
    
    		if(screen==0){ //enter digit 1
    
    			LCDdisplay(0,1,"_____ - ____ - ____");
    
    			li1=set_val(0,1,0,9,li1,1);
    
    			if(last_btn_clicked==3){
    
    				screen=1;
    
    			}
    
    		}
    
    		else if(screen==1){ //enter digit 2
    
    			li2=set_val(1,1,0,9,li2,1);
    
    			if(last_btn_clicked==3){
    
    				screen=2;
    
    			}
    
    		}
    
    		else if(screen==2){ //enter digit 3
    
    			li3=set_val(2,1,0,9,li3,1);
    
    			if(last_btn_clicked==3){
    
    				screen=3;
    
    			}
    
    		}
    
    		else if(screen==3){ //enter digit 4
    
    			li4=set_val(3,1,0,9,li4,1);
    
    			if(last_btn_clicked==3){
    
    				screen=4;
    
    			}
    
    		}
    
    		else if(screen==4){ //enter digit 5
    
    			li5=set_val(4,1,0,9,li5,1);
    
    			if(last_btn_clicked==3){
    
    				screen=5;
    
    			}
    
    		}
    
    		
    
    		//************************************************************
    
    		//                                            Enter set two
    
    		//************************************************************
    
    		else if(screen==5){ //enter digit 6
    
    			li6=set_val(8,1,0,9,li6,1);
    
    			if(last_btn_clicked==3){
    
    				screen=6;
    
    			}
    
    		}
    
    		else if(screen==6){ //enter digit 7
    
    			li7=set_val(9,1,0,9,li7,1);
    
    			if(last_btn_clicked==3){
    
    				screen=7;
    
    			}
    
    		}
    
    		else if(screen==7){ //enter digit 8
    
    			li8=set_val(10,1,0,9,li8,1);
    
    			if(last_btn_clicked==3){
    
    				screen=8;
    
    			}
    
    		}
    
    		else if(screen==8){ //enter digit 9
    
    			li9=set_val(11,1,0,9,li9,1);
    
    			if(last_btn_clicked==3){
    
    				screen=9;
    
    			}
    
    		}
    
    		//************************************************************
    
    		//                                            Enter set three
    
    		//************************************************************
    
    		
    
    		else if(screen==9){ //enter digit 10
    
    			li10=set_val(15,1,0,9,li10,1);
    
    			if(last_btn_clicked==3){
    
    				screen=10;
    
    			}
    
    		}
    
    		else if(screen==10){ //enter digit 11
    
    			li11=set_val(16,1,0,9,li11,1);
    
    			if(last_btn_clicked==3){
    
    				screen=11;
    
    			}
    
    		}
    
    		else if(screen==11){ //enter digit 12
    
    			li12=set_val(17,1,0,9,li12,1);
    
    			if(last_btn_clicked==3){
    
    				screen=12;
    
    			}
    
    		}
    
    		else if(screen==12){ //enter digit 13
    
    			li13=set_val(18,1,0,9,li13,1);
    
    			if(last_btn_clicked==3){
    
    				screen=13;
    
    			}
    
    		}
    
    		else if(screen==13){
    
    			//**************************************************
    
    			//                          Validate Login Structure
    
    			//**************************************************
    
    			if(li5==0){
    
    				vi1=li6;
    
    				vi2=li7;
    
    				vi3=li8;
    
    				vi4=li13;
    
    				vi5=li10;
    
    				vi6=li9;
    
    				vi7=li11;
    
    				vi8=li12;
    
    			}
    
    			else if(li5==1){
    
    				vi1=li7;
    
    				vi2=li9;
    
    				vi3=li8;
    
    				vi4=li13;
    
    				vi5=li12;
    
    				vi6=li11;
    
    				vi7=li10;
    
    				vi8=li6;
    
    			}
    
    			else if(li5==2){
    
    				vi1=li8;
    
    				vi2=li10;
    
    				vi3=li9;
    
    				vi4=li6;
    
    				vi5=li7;
    
    				vi6=li11;
    
    				vi7=li12;
    
    				vi8=li13;
    
    			}
    
    			else if(li5==3){
    
    				vi1=li9;
    
    				vi2=li13;
    
    				vi3=li11;
    
    				vi4=li10;
    
    				vi5=li8;
    
    				vi6=li12;
    
    				vi7=li6;
    
    				vi8=li7;
    
    			}
    
    			else if(li5==4){
    
    				vi1=li10;
    
    				vi2=li13;
    
    				vi3=li11;
    
    				vi4=li6;
    
    				vi5=li8;
    
    				vi6=li9;
    
    				vi7=li12;
    
    				vi8=li7;
    
    			}
    
    			else if(li5==5){
    
    				vi1=li11;
    
    				vi2=li10;
    
    				vi3=li12;
    
    				vi4=li7;
    
    				vi5=li9;
    
    				vi6=li8;
    
    				vi7=li6;
    
    				vi8=li13;
    
    			}
    
    			else if(li5==6){
    
    				vi1=li12;
    
    				vi2=li11;
    
    				vi3=li9;
    
    				vi4=li10;
    
    				vi5=li8;
    
    				vi6=li7;
    
    				vi7=li13;
    
    				vi8=li6;
    
    			}
    
    			else if(li5==7){
    
    				vi5=li13;
    
    				vi6=li11;
    
    				vi4=li6;
    
    				vi1=li9;
    
    				vi8=li7;
    
    				vi7=li8;
    
    				vi2=li12;
    
    				vi3=li10;
    
    			}
    
    			else if(li5==8){
    
    				vi5=li13;
    
    				vi4=li9;
    
    				vi6=li12;
    
    				vi3=li8;
    
    				vi1=li11;
    
    				vi7=li6;
    
    				vi2=li10;
    
    				vi8=li7;
    
    			}
    
    			else if(li5==9){
    
    				vi1=li7;
    
    				vi2=li9;
    
    				vi3=li6;
    
    				vi4=li12;
    
    				vi5=li8;
    
    				vi6=li10;
    
    				vi7=li11;
    
    				vi8=li13;
    
    			}
    
    			parseA=((vi1*1000)+(vi2*100)+(vi3*10)+vi4) + ((li1*100)+(li3*10)+li5);
    
    			parseB=((vi5*1000)+(vi6*100)+(vi7*10)+vi8) + ((li2*10)+li4);
    
    			pass=1;
    
    			if((cutterNo-parseA)!=10 && (cutterNo-parseA)!=5 && (cutterNo-parseA)!=1){
    
    				pass=0;
    
    			}
    
    			if((cutterNo-parseB)!=10 && (cutterNo-parseB)!=5 && (cutterNo-parseB)!=1){
    
    				pass=0;
    
    			}
    
    			if((cutterNo-parseA) != (cutterNo-parseB)){
    
    				pass=0;
    
    			}
    
    			if(pass){
    
    				//name the user file
    
    				user_time=(cutterNo-parseA)*60;
    
    				// index the array
    
    				//int index = 0;
    
    
    
    				//copy the unique name into the new array
    
    				user_file[0] = li1;
    
    				user_file[1] = li2;
    
    				user_file[2] = li3;
    
    				user_file[3] = li4;
    
    				user_file[4] = li5;
    
    
    
    				// now add what ever other filename identification you like
    
    				user_file[5] = '.';
    
    				if(user_time==60){
    
    					user_file[6] = 'o';
    
    					user_file[7] = 'n';
    
    					user_file[8] = 'e';
    
    				}
    
    				else if(user_time==300){
    
    					user_file[6] = 'f';
    
    					user_file[7] = 'i';
    
    					user_file[8] = 'v';
    
    				}
    
    				else if(user_time==600){
    
    					user_file[6] = 't';
    
    					user_file[7] = 'e';
    
    					user_file[8] = 'n';
    
    				}
    
    				// and null terminate the string
    
    				user_file[9] = '\0';
    
    
    
    				screen=14;
    
    			}
    
    			else{
    
    				//itoa(parseA, buffer, 10);
    
    				//LCDdisplay(0,1,buffer);
    
    				//itoa(parseB, buffer, 10);
    
    				//LCDdisplay(0,2,buffer);
    
    				LCDdisplay(0,2,"Invalid Login       ");
    
    				LCDdisplay(0,3,"Press Reset         ");
    
    			}
    
    
    
    		}
    
    		else if(screen==14){
    
    			//see if the card is in the card holder
    
    			sd_card(1);
    
    			if(dpError==0){
    
    				//mount the card
    
    				//sd_card(2);
    
    			}
    
    			if(dpError==0){
    
    				//create a file and store initial values
    
    				//sd_card(3);
    
    			}
    
    			
    
    			loop=0;
    
    			
    
    		}
    
    		
    
    	}//end of loop
    
    
    
    	state=2;
    
    	screen=0;
    
    }
    Last edited by dallypost; 03-18-2010 at 03:40 PM.

  7. #7
    Registered User
    Join Date
    Apr 2006
    Posts
    2,017
    Here's your error:
    Code:
    extern char user_file[20];
    Though I can't say I support your use of globals.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  8. #8
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    You have "extern char user_file". This is not a pointer nor an array. Modify it to whatever type you actually intend it to be in the C file where it is declared.

  9. #9
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Quote Originally Posted by King Mir View Post
    Here's your error:
    Code:
    extern char user_file[20];
    Though I can't say I support your use of globals.
    We seem to have posted at the same time. Credit goes to you though you were 1 minute faster than me .

  10. #10
    Registered User
    Join Date
    Jun 2009
    Posts
    5
    Though I can't say I support your use of globals.
    I am green but learning. When someone suggests that there is a better way, I want to know more. I have a group of variables that must be available to virtually every function in my program. I have declared them globally and externed then to the functions that need them. If there is a better way, please point me in that direction.

    BTW, our project is kind of cool http://www.dallypost.com/dp/article....yPost%20Cutter
    Last edited by dallypost; 03-18-2010 at 03:51 PM.

  11. #11
    Registered User
    Join Date
    Jun 2009
    Posts
    5
    Thanks for your help, everything is working great

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. Replies: 16
    Last Post: 10-29-2006, 04:04 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 03:49 AM

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