Thread: output to file

  1. #1
    Unregistered
    Guest

    output to file

    Does anybody know how to output the results to a file instead of printf ob the screen? Thanks

    The following is a bit of my code:

    #include<stdio.h>
    #include<stdlib.h>
    #include<math.h>



    void direction()
    {

    float a, b, c;
    int x1,y1,z1,x2,y2,z2;
    int u1, v1, w1, u2, v2, w2;
    float I_u1v1w1, I_u2v2w2;
    float phi;
    float L;
    float alpha, beta, gama;
    char ch, discard;

    printf("---Caculating the angle between zone axis---\n");

    do
    {
    printf("Enter the lattice parameters(postive integer):");
    printf("\na=");
    scanf("%f", &a);
    discard = getchar();
    printf("b=");
    scanf("%f", &b);
    discard = getchar();
    printf("c=");
    scanf("%f", &c);
    discard = getchar();
    printf("alpha=");
    scanf("%f", &alpha);
    discard = getchar();
    printf("beta=");
    scanf("%f", &beta);
    discard = getchar();
    printf("gama=");
    scanf("%f", &gama);
    discard = getchar();
    printf("\nEnter the number of (u1 v1 w1):");
    scanf("%d %d %d", &u1, &v1, &w1);
    discard = getchar();
    printf("\nEnter the number of (u2 v2 w2):");
    scanf("%d %d %d", &u2, &v2, &w2);
    discard = getchar();

    alpha = alpha * PI/180;
    beta = beta * PI/180;
    gama = gama * PI/180;

    printf("\nu1v1w1\tu2v2w2\tphi");

    for(x1=-u1; x1<=u1; x1++)
    {
    for(y1=-v1; y1<=v1; y1++)
    {
    for(z1=-w1; z1<=w1; z1++)
    {
    for(x2=-u2; x2<=u2; x2++)
    {
    for(y2=-v2; y2<=v2; y2++)
    {
    for(z2=-w2; z2<=w2; z2++)
    {

    L = a*a*x1*x2 + b*b*y1*y2 + c*c*z1*z2 + b*c*(y1*z2+z1*y2)*
    cos(alpha) + a*c*(z1*x2 + x1*z2)*cos(beta) + a*b*(x1*y2+y1*x2)*cos(gama);

    I_u1v1w1 = a*a*x1*x1 + b*b*y1*y1 + c*c*z1*z1 + 2*b*c*y1*z1*
    cos(alpha) + 2*c*a*x1*z1*cos(beta) + 2*a*b*x1*y1*cos(gama);

    I_u2v2w2 = a*a*x2*x2 + b*b*y2*y2 + c*c*z2*z2 + 2*b*c*y2*z2*
    cos(alpha) + 2*c*a*x2*z2*cos(beta) + 2*a*b*x2*y2*cos(gama);

    phi = acos( L/sqrt(I_u1v1w1*I_u2v2w2)) * 180/PI;
    printf("\n%d%d%d\t%d%d%d\t%.3f",
    x1,y1,z1,x2,y2,z2,phi);

    }
    }
    }
    }
    }
    }

    getchar();/*to remove the effect of "Enter" when input 'y' or 'n'*/
    printf("\ncomputer more?(y/n)");
    scanf("%c",&ch);

    } while(ch == 'y');
    }

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    Wow, this has been done approximately 6000 times. Use the handy-dandy search.

  3. #3
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    searching for output to a file comes up with 299 related threads...

    My guess is you will find what you want there.
    Blue

  4. #4
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    BTW, how is this C++ and not C code?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  2. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  3. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  5. Simple File Creation Algorithm
    By muffin in forum C Programming
    Replies: 13
    Last Post: 08-24-2001, 03:28 PM