errors with void

This is a discussion on errors with void within the C Programming forums, part of the General Programming Boards category; hi again pals I am trying to implemnt my source from fortran to c, using void instead subroutines as in ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    24

    errors with void

    hi again pals
    I am trying to implemnt my source from fortran to c, using void instead subroutines as in fortran but something is wrong could you help me
    here is my source
    Code:
    /*Laplace equation 2D*/
    /*Build the Mesh*/
    #include<stdio.h>
    #include<stdlib.h>
    #include<math.h>
    #define max 100
    int 
    main()
    {
    	FILE *mesh;
    	float dx,x[max],y[max],f[max][max],u[max][max],v[max][max],c[max][max];
    	float ys,xs,il,it,ui;
    	
    	int imax,jmax,i,j,s;
    	mesh=fopen("mesh.data","w");
    	
    	il=11;
    	it=31;
    	imax=41;
    	jmax=12;
    	ys=1.24;
    	xs=1.24;
    	ui=0.5;
    	/*Generating the Mesh*/
    	dx=-1.0/(il-it);
    	
    	for (i=il;i<=it;i++)
    	{
    		x[i]=(i-il)*dx;
    		
    	}
    	for (i=it+1;i<=imax;i++)
    	{
    		x[i]=x[i-1]+(x[i-1]-x[i-2])*xs;
    		
    	}
    	for(i=il-1;i>=1;i--)
    	{
    	    x[i]=x[i+1]+(x[i+1]-x[i+2])*xs;
    	    
    	}
    	y[1]=-dx/2;
    	y[2]=dx/2;
    	for(j=3;j<=jmax;j++)
    	{
    	    y[j]=y[j-1]+(y[j-1]-y[j-2])*ys;
    	}
    	
    	/*Print the Results*/
    	for(j=1;j<=jmax;j++)
    	{
    		for(i=1;i<=imax;i++)
    		fprintf(mesh,"%1.15f  %1.15f\n",x[i],y[j]);
    	}
    	fclose(mesh);
    	/*Initial Conditions*/
    	for(i=1;i<=imax;i++)
    	{
    		for(j=1;j<=jmax;j++)
    		f[i][j]=ui*x[i];
    		
    	}
    	/*Calculus of Velocities*/
    	for(i=2;i<=imax-1;i++)
    	{
    		for(j=2;j<=jmax-1;j++)
    		u[i][j]=(f[i+1][j]-f[i-1][j])/(x[i+1]-x[i-1]);
    		v[i][j]=(f[i][j+1]-f[i][j-1])/(y[j+1]-y[j-1]);
    		c[i][j]=1.0-(power(u[i][j],2)+power(v[i][j],2));
    	}
    	
    	
        void contour(float f[][],float x[],float y[],int jmax, int imax)
    	{
    	for(j=1;j<=jmax;j++)
    	{
    		f[1][j]=ui*x[1];
    		f[imax][j]=ui*x[imax];
    	}
    	for(i=1;i<=imax;i++)
    	{
    		f[i][jmax]=ui*x[i];
    		if((i>=il) && (i<=it))
    		f[i][1]=f[i][2]-0.1*(y[2]-y[1])*(1.0-2*x[i]);
    		else
    		f[i][1]=f[i][2];
    	}
    	}// end contour ()
              	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	exit(0);
    }

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    Functions cannot be placed inside each other.
    Beware of things like this:
    Code:
    		for(j=2;j<=jmax-1;j++)
    		u[i][j]=(f[i+1][j]-f[i-1][j])/(x[i+1]-x[i-1]);
    		v[i][j]=(f[i][j+1]-f[i][j-1])/(y[j+1]-y[j-1]);
    		c[i][j]=1.0-(power(u[i][j],2)+power(v[i][j],2));
    Which is the same as:
    Code:
    		for(j=2;j<=jmax-1;j++)
    		{
    			u[i][j]=(f[i+1][j]-f[i-1][j])/(x[i+1]-x[i-1]);
    		}
    		v[i][j]=(f[i][j+1]-f[i][j-1])/(y[j+1]-y[j-1]);
    		c[i][j]=1.0-(power(u[i][j],2)+power(v[i][j],2));
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    24
    my question is other, concerning to void in my source I dont get to run it

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You are defining your function within another function. As far as I know, only gcc allows this behaviour. Move it outside of main, and it will probably compile. If it still doesn't compile, please post the error messages.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Mar 2009
    Posts
    24
    well it still doesnt compile i have this error
    Code:
    	for(j=1;j<=jmax;j++)
    	{
    		f[1][j]=ui*x[1];
    		f[imax][j]=ui*x[imax];
    	}
    Error : arithmetic on pointer to an incomplete type

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, that's what I commented in the other thread on the same subject. It's the fact that you haven't described the size of the f array.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inserting a swf file in a windows application
    By face_master in forum Windows Programming
    Replies: 12
    Last Post: 05-03-2009, 11:29 AM
  2. Case Statement
    By danlee58 in forum C Programming
    Replies: 16
    Last Post: 11-23-2008, 07:46 PM
  3. Error, not sure what it means.
    By RealityFusion in forum C++ Programming
    Replies: 1
    Last Post: 09-25-2005, 01:17 PM
  4. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 03:58 PM
  5. Quack! It doesn't work! >.<
    By *Michelle* in forum C++ Programming
    Replies: 8
    Last Post: 03-01-2003, 11:26 PM

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