Thread: help in writing a C-Progrm

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

  2. #2
    Registered User
    Join Date
    Sep 2007
    Posts
    17

    no

    Hi, i dont have any programming experience...just started 1 week before...just for this work which i posted.... i started reading....
    Kumar

  3. #3
    Registered User
    Join Date
    Jun 2007
    Posts
    63
    Well i dont hnow what exactly you want to calc. I coded a bit, but i am not responsible for what the resulst are or what you really want to do with it. Look at the code and tell me what you dont understand.
    Code:
    //---------------------------------------------------------------------------
    
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <math.h>
    #include <conio.h>
    
    #define PI 3.14159265
    
    #pragma hdrstop
    
    //---------------------------------------------------------------------------
    //Functions Prototypes.
    double mFunction(double b, double gamma)
    {
    	return b * cos(gamma * PI / 180);
    }
    double nFunction(double c, double beta)
    {
    	return c * cos(beta * PI / 180);
    }
    double gFunction(double b, double gamma)
    {
    	return b * sin(gamma * PI / 180);
    }
    double SquareRootT(double c, double n, double h)
    {
    	double R = pow(c,2) - pow(n,2) - pow(h,2);
    	if(R < 0)
    		R = -R;
    	return sqrt(R);
    }
    double hFunction(double c, double alfa, double beta, double gamma)
    {
    	return (c/ sin(gamma * PI / 180)) * (cos(alfa * PI /180)) - (cos(beta * PI / 180) * cos(gamma * PI / 180));
    }
    
    void CreateNewFile(char *oldFile, char *nFile,double a, double b, double c, double alfa, double beta, double gamma)
    {
    	if(!oldFile || !nFile)
    	{
    		printf("Error, NULL parametres.\n");
    		return;
    	}
    	else
    	{
    		FILE *of = fopen(oldFile, "r");
    		FILE *nf = fopen(nFile, "w");
    		//Variables.
    		double Col1 = 0.0;
    		double Col2 = 0.0;
    		double Col3 = 0.0;
    		//Array to hold the numbers.
    		double arr[3] = {0.0,0.0,0.0};
    		if(!of)
    		{
    			fprintf(stderr, "Error can not open '&#37;s' file.\n", oldFile);
    			return;
    		}
    		if(!nf)
    		{
    			fprintf(stderr, "Error can not open '%s' file.\n", nFile);
    			return;
    		}
    		while(fscanf(of,"%lf\t%lf\t%lf\n", &arr[0], &arr[1], &arr[2]) != EOF)
    		{
    			//Weird numbers.
    			Col1 = a * arr[0] + arr[1] * mFunction(b, gamma) + arr[2] * nFunction(c, beta);
    			Col2 = arr[1] * gFunction(b, gamma) + arr[2] * hFunction(c, alfa, beta, gamma);
    			Col3 = arr[2] * SquareRootT(c, nFunction(c, beta), hFunction(c, alfa, beta, gamma));
    
    			//Got the numbers write them down to file.
    			fprintf(nf,"%lf\t%lf\t%lf\n", Col1,Col2,Col3);
    			//Zero the values for next iteration.
    			arr[0] = 0.0;
    			arr[1] = 0.0;
    			arr[2] = 0.0;
    		}
    		fclose(nf);
    		fclose(of);
    	}
    
    }
    
    //---------------------------------------------------------------------------
    
    #pragma argsused
    int main(int argc, char* argv[])
    {
    	CreateNewFile("numbers.txt", "result.txt", 1.234, 3.456, 3.4534, 2.56, 4.78, 8.98);
    	printf("Hit any key to continue......");
    	getch();
    	return 0;
    }
    //---------------------------------------------------------------------------
    If you run the program it will create a new file in the debug folder that will hold the results. Have a look at them and tell me,
    Bokarinho!!!
    /Edit: Dont forget that the numbers.txt is the input file.
    Last edited by Bokarinho; 09-22-2007 at 04:41 PM. Reason: Forgot!!!

  4. #4
    Registered User
    Join Date
    Sep 2007
    Posts
    17

    hi

    Hi Bokarinho,
    thanks...i have the correct converted values...i made it by excel...i think i can understand a bit of ur program...now i am in home...may be in 2 hrs will go to my inst. and test and tell u the results....actually my need is to convert Cartesian coordinates in to lattice coordinate...that my purpose...
    thanks again..
    Kumar

  5. #5
    Registered User
    Join Date
    Sep 2007
    Posts
    17

    hi

    Hi Robwhit,
    i am interested in learning...next month planned to buy a book by yeswhat kanetkar...

  6. #6
    Registered User
    Join Date
    Sep 2007
    Posts
    17

    hi Bokariho

    Hi got a problem..when i compile, it says 'lattice.c:5:19: error: conio.h: No such file or directory.
    My operating system is suse linux...I copied ur program in to a file and named as lattice.c
    and when i compiled....using cc -lm -o ~/bin/lattice lattice.c [here lattice is my exe file and lattice.c is your source code....so that exe file will be copied in to my bin folder]...
    can you suggest me what to do!!!!
    Kumar

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 05-20-2008, 08:57 AM
  2. Very slow file writing of 'fwrite' function in C
    By scho in forum C Programming
    Replies: 6
    Last Post: 08-03-2006, 02:16 PM
  3. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 398
    Last Post: 10-11-2005, 08:44 AM
  4. help! fifo read problem
    By judoman in forum C Programming
    Replies: 1
    Last Post: 08-16-2004, 09:19 AM
  5. Writing Bitmap Files
    By HappyDude in forum C++ Programming
    Replies: 1
    Last Post: 10-13-2001, 05:48 PM