saving a file

This is a discussion on saving a file within the C Programming forums, part of the General Programming Boards category; This might sound complicated but PLEASE bear with me! What I am doing is giving the user the choice to ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    13

    Unhappy saving a file

    This might sound complicated but PLEASE bear with me!
    What I am doing is giving the user the choice to save a file in a number of ways...

    if (Select==1)
    BasicSaveStructure(), SaveNormal();
    else if (Select==2)
    BasicSaveStructure(), Save90();
    else if (Select==3)
    BasicSaveStructure(), Save180();
    else if (Select==4)
    BasicSaveStructure(), Save270();
    else if (Select==5)
    BasicSaveStructure(), SaveInvert();
    else if (Select==6)
    BasicSaveStructure(), SaveInvert90();
    else if (Select==7)
    BasicSaveStructure(), SaveInvert180();
    else if (Select==8)
    BasicSaveStructure(), SaveInvert270();
    else if (Select==9)
    main();

    ie. what the user selects then it will go to that particular section. All options to go the first section which deals with the basic of saving a file...

    printf("Please enter the name of the file to save your image: ");
    gets(Filename);
    OutputFile=fopen(Filename, "w");
    if (OutputFile==NULL)
    {
    printf("Cannot save file of that name\n");
    printf("The program will now end\n");
    GetInteger();
    exit(1);
    }
    printf("\nImage file has been successfully saved\n");
    printf("Press any key to return to the main menu\n");
    GetInteger();

    after that i need to go to the corresponding function to save the file in the way the user wants it. What I don't know is how to run the contents of a function and save it at the same time. I have included one of the functions that I am using in my program...

    void Rotate90(void)
    {
    clrscr();

    for (i=0;i<ROWS;i++)
    for (j=0;j<COLS;j++)
    Picture2[COLS-1-j][i]=Picture[i][j];
    }

    but i don't know how to call that function and perform the save section at the same time.

    ***THANK YOU SO MUCH FOR ANY HELP ON THIS SUBJECT***

  2. #2
    Unregistered
    Guest
    Why don't you make any changes on the image and then have an option to save it? That way you only have to code the saving routine once and have options to actually change the image and then another option to save it as it is with the current changes.

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    Yes, convert the image in memory prior to writing it to disk. That way you can use one file writing function and a simple algorithm to alter or rotate the data. Since the data has already been changed to meet your needs, when the file writing function writes the file it will be written as it is in memory. Much simpler.

    What's this for? More info would be helpful.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 03:29 PM
  2. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 02:04 PM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 11:12 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 05:10 PM

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