Thread: scanning and writing data to a file simultaneously

  1. #1
    Registered User
    Join Date
    Aug 2001

    Question scanning and writing data to a file simultaneously

    I want the program to offer the possibility to make a new project. Then the user needs to enter a name for the new project (creating a file), and different values for all the variables. I was wondering if I could save the data into the file at the ame time the user is entering the new values for the variables. I've tried this:


    char file_name[8];
    double LOA, I, J, P, E, D, GM, H1, H2, H3, S1, S2, S3;
    FILE *output;


    printf("Write the name of the new project \n");
    scanf("%s", file_name);
    outp = fopen(file_name, "w");
    printf("Please enter the characteristics of the new project
    printf("All the values are to be entered in meters, except t
    printf("\nwhich is in kilograms");

    printf("\nLOA: ");
    scanf("%lf", &LOA);
    fprintf(outp, "%.2f\n", LOA);
    printf("\nI: ");
    scanf("%lf", &I);
    fprintf(outp, "%.2f\n", I);
    printf("\nJ: ");
    scanf("%lf", &J);
    fprintf(outp, "%.2f\n", J);
    printf("\nP: ");
    scanf("%lf", &P);
    fprintf(outp, "%.2f\n", P);
    printf("\nE: ");
    scanf("%lf", &E);
    fprintf(outp, "%.2f\n", E);
    printf("\nDisplacement (in kilograms): ");
    scanf("%lf", &D);
    fprintf(outp, "%.2f\n", D);
    printf("\nGM: ");
    scanf("%lf", &GM);
    fprintf(outp, "%.2f\n", GM);
    printf("\nH1: ");
    scanf("%lf", &H1);
    fprintf(outp, "%.2f\n", H1);
    printf("\nH2: ");
    scanf("%lf", &H2);
    fprintf(outp, "%.2f\n", H2);
    printf("\nH3: ");
    scanf("%lf", &H3);
    fprintf(outp, "%.2f\n", H3);
    printf("\nS1: ");
    scanf("%lf", &S1);
    fprintf(outp, "%.2f\n", S1);
    printf("\nS2: ");
    scanf("%lf", &S2);
    fprintf(outp, "%.2f\n", S2);
    printf("\nS3: ");
    scanf("%lf", &S3);
    fprintf(outp, "%.2f\n", S3);


    printf("\n\n Press any key to continue");


    And I'm getting this errors:

    Error TURBOC\CODE\VERS_01.C 98: Lvalue required
    Warning TURBOC\CODE\VERS_01.C 104: Suspicious pointer conversion
    Warning TURBOC\CODE\VERS_01.C 107: Suspicious pointer conversion

    I've been able to do functions that write files before, but not "mixing" them at the same time with the input functions as I'm trying now. I'm sure it's completely wrong, but I don't know what to try.

    Any ideas?

    P.D.: don't laugh too much for my code

  2. #2
    Registered User
    Join Date
    Aug 2001
    I've seen the mistake by myself, sorry, I didn't pay enough attention. I used output and outpt, when I should use only one of them. Now I don't have errors or warnings.

    Still, can you tell me if it's the proper way to do it?

Popular pages Recent additions subscribe to a feed