"Assignment makes integer from pointer without a cast"

This is a discussion on "Assignment makes integer from pointer without a cast" within the C Programming forums, part of the General Programming Boards category; I am working on a code that reads a CSV file and sorts it into separate arrays. I'm not sure ...

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    11

    "Assignment makes integer from pointer without a cast"

    I am working on a code that reads a CSV file and sorts it into separate arrays.
    I'm not sure what I'm doing wrong, but I'm getting "assignment makes integer from pointer without a cast" at each first line of the internal while loops (the ones that only have "{" in them). Anyone have a clue what I'm doing wrong?

    Code:
    /*read file*/
    char arra [2000] [100] ;
    char line [2000];
    
    for( row = 0; row < 2000; row++ )	
    	for( column = 0; column < 100; column++ )
    		arra [row] [column] = '\0' ;
    
    		for (row = 0; row < 5; row++)
    			line [row] = '\0' ;
    
    			if ( fp != NULL)
    			{
    				while (fgets (line, sizeof line, fp ) != NULL) /*read a line*/
    				{
    					strcpy (arra[row], line) ;
    					/*printf ("array --> %s", &arra[row]) ;*/
    					row++;
    				}
    				
    				/*split up rows into separate arrays*/
    				char codes [2000][4] ;
    				char names [2000][15] ;
    				char alts [2000][10];
    				char lats [2000][10] ;
    				char longis [2000][10] ;
    				char states [2000][2];
    				int character = 0 ;
    				char temp ;
    				char *check ;
    				char *comma ;
    				
    				row = 1 ;
    				check = arra[row,character] ;
    				comma = ',' ;
    				
    				for ( row = 1; row <2000 ; row ++) 
    					while ( strcmp ( check, comma ) != 0 )
    					{
    						temp = arra [row, character] ;
    						codes [row, character ] = temp ;
    						character++ ;
    						check = arra[row,character] ;
    					}
    					while ( strcmp ( check, comma ) != 0 )
    					{
    						temp = arra [row, character] ;
    						names[row][character] = temp ;
    						character++ ;
    						check = arra[row,character] ;
    					}
    					while ( strcmp ( check, comma ) != 0 )
    					{
    						temp = arra [row, character] ;
    						states[row][character] = temp ;
    						character++ ;
    						check = arra[row,character] ;
    					}
    					while ( strcmp ( check, comma ) != 0 )
    					{
    						temp = arra [row, character] ;
    						lats[row][character] = temp ;
    						character++ ;
    						check = arra[row,character] ;
    					}
    					while ( strcmp ( check, comma ) != 0 )
    					{
    						temp = arra [row, character] ;
    						longis[row][character] = temp ;
    						character++ ;
    						check = arra[row,character] ;
    					}
    					while ( strcmp ( check, '\n' ) != 0 )
    					{
    						temp = arra [row, character] ;
    						alts[row][character] = temp ;
    						character++ ;
    						check = arra[row,character] ;
    					}
    				fclose(fp) ;
    			}
    			else
    			{
    				perror( filename) ;
    			}

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    This is not good syntax in C:

    check = arra[row,character] ; //not OK

    check = arra[row][character]; //OK

    And I wouldn't use strcmp() to find your comma's. Just

    while(array[row][char++] != ',');

    should do.

  3. #3
    Registered User
    Join Date
    Jun 2010
    Posts
    11
    Thanks for the heads up on the syntax, I'm still pretty new to C.
    I corrected as per your suggestions, but I'm getting the same error, now on the line in each while loop that reassigns the check variable.

  4. #4
    Registered User
    Join Date
    Jun 2010
    Posts
    11
    I removed the pointer "*" from the check variable and it compiles, but returns a segmentation fault when i run the output file.

  5. #5
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,832
    The comma pointer doesn't point to anywhere. Remove the '*' from that.

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    for every row, for every column, for every row, you're creating:

    Code:
    				
    				/*split up rows into separate arrays*/
    				char codes [2000][4] ;
    				char names [2000][15] ;
    				char alts [2000][10];
    				char lats [2000][10] ;
    				char longis [2000][10] ;
    				char states [2000][2];
    				int character = 0 ;
    				char temp ;
    				char *check ;
    				char *comma ;
    statically.

    First, I believe this is far more arrays than you actually need, or intended, and second, it's more than you can create on the stack.

    From your input, how many names[] arrays, do you actually need? (in total). I want the number, not the description, and I want to know what arithmetic you used, to find that number, in a simple equation, like this:

    "Example:
    There are 2,000 rows, each row has 3 names in it:

    Number of names[] arrays = 2,000 * 3

    Do that math, and adjust your program.

    Then repost your current code in this function AND post up a 10 line sample of data input, and data output after this function (or block of code within this function).

    Since I don't know exactly what you're doing with this data, I usually defer the number of data structures, to the student's good judgment. Here, your judgment on the number of data structures, has jumped the rails, I suspect.


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help assignment due tomorrow
    By wildiv in forum C Programming
    Replies: 6
    Last Post: 01-27-2010, 07:38 PM
  2. Replies: 4
    Last Post: 01-27-2009, 01:33 PM
  3. "assignment makes integer from pointer without a cast"
    By Freez3L in forum C Programming
    Replies: 4
    Last Post: 11-04-2002, 03:26 AM
  4. assignment makes pointer from integer
    By crescen7 in forum C Programming
    Replies: 4
    Last Post: 06-25-2002, 10:08 PM
  5. Replies: 3
    Last Post: 01-14-2002, 11:13 AM

Tags for this Thread


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