Thread: getting subscripted value is neither array nor pointer error

  1. #1
    Registered User
    Join Date
    Sep 2009

    getting subscripted value is neither array nor pointer error

    int get_circuit(void)
       char buffer[100] = {0};  /* initialized to zeroes */
       int i,a, rc;
    	float x;	
    	char member0[10] = "test";
       FILE *fp = fopen(FILE_NAME_IN,"r");
       if (fp == NULL) {
         perror("Failed to open file \"myfile\"");
       return EXIT_FAILURE;
       for (i = 0; (rc = getc(fp)) != EOF && i < 	100; buffer[i++] = rc)
    	//print out the contents of buffer
    		printf("buffer[%i] = %c\n",i,buffer[i]);
    		if(buffer[i]==' ');
    			x = atoi(buffer);
    		printf("x = %f",x);
    	printf("ready to print the array");
    	strcpy(x[0].name,member0);        //<- this is the line it refers to
      	return EXIT_SUCCESS;
    The structure defined as a globlal

    struct components
    char name[20];
    float value;

    Thanks in advance, Mick

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    London, United Kingdom
    x refers to float x in this context not to your x[10] components array. Rename that float variable to something else in that function.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

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. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  3. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  5. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM