passing argument 1 of 'fscanf' from incompatible pointer type

This is a discussion on passing argument 1 of 'fscanf' from incompatible pointer type within the C Programming forums, part of the General Programming Boards category; Hey, im trying to write a program that computes the determinant of a 3x3 matrix from another file. Ive only ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    12

    passing argument 1 of 'fscanf' from incompatible pointer type

    Hey, im trying to write a program that computes the determinant of a 3x3 matrix from another file. Ive only tried to input the file so far and i keep getting the error 'passing argument 1 of 'fscanf' from incompatible pointer type' but cant work out whats wrong.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
      
    #define orderOfMatrix 3
      
      int main(int argc, char* argv[])
     { 
      
     FILE         *input;
     const char    inp_fn[]="matrix.dat";
     int 	i, j, m[3][3], det;
     
     /*Open file */
      input = fopen(inp_fn, "r");
      
      /* Check the pointers to files are not NULL */
        if( (input != (FILE*) NULL))
    	{
    	for(i=0; i<orderOfMatrix; i++)
    	 {
    		for(j=0; j<orderOfMatrix; j++)
    		{
    			fscanf(inp_fn, "%lf \n", &m[i][j]);  
    		}
    	 }
    		return 0;
    	}
      else
        {
    	 printf("*** Could not open input file! ***\n");
    	}
    	 
    	/*close file */
    	fclose(input);
    		
    	return(EXIT_SUCCESS);
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    You pass the FILE* variable, not the filename.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    12
    ah of course, works now, thank you!

  4. #4
    Registered User
    Join Date
    Dec 2010
    Posts
    1

    the same question

    Code:
    #include "stdio.h"
    main(int argc,char *argv[])
    {
    	int i;
    	char name[20];
    	unsigned char *s;
    	void load(unsigned char *,char *);
    	printf("Input open filename:\n");
    	fscanf("%s",name);
    	i=0;
    	s=(unsigned char *) malloc(sizeof(unsigned char)*1000);
    	load(s,name);
    	while(*s);
    	{
    		if(1%30==0)
    			printf("\n");
    			s++;
    			i++;
    	}
    	free(s);
    }
    void load (unsigned char *s,char name[])
    {
    	FILE *fp;
    	if((fp=fopen(name,"rb"))==NULL)
    	{
    		fprintf(stderr,"cannot open this file.\n");
    		return;
    	}
    	fread(s,sizeof(unsigned char ),1000,fp);
    	fclose(fp);
    	return;
    }
    "9: warning: passing arg 1 of `fscanf' from incompatible pointer type"
    I still do not understand!!
    why?
    It's here----fscanf("%s",name);
    any quetion?

  5. #5
    Registered User
    Join Date
    Aug 2010
    Posts
    231
    No question but an answer:
    fscanf needs a Filepointer as first argument.
    #include "stdio.h" is newbie stuff, better is
    #include <stdio.h>

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. LDAP Query
    By Travoiz in forum C++ Programming
    Replies: 0
    Last Post: 08-13-2009, 02:58 PM
  2. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 06:33 AM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM

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