Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9283417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:37:37+00:00 2026-06-18T18:37:37+00:00

I need som help with this code: int main(int argc, char** argv) { char

  • 0

I need som help with this code:

int main(int argc, char** argv)
{
    
    char text[500]; /* Create a character array that will store all of the text in the file */
    char line[100]; /* Create a character array to store each line individually */
    
    FILE *file; /* Create a pointer to the file which will be loaded, to allow access to it */
    char fileName[30]; /* Create a character array to store the name of the file the user want to load */
    
    printf("Enter the name of the file containing ship information: ");
    scanf("%s", fileName);
    
    /*Try to open the file specified by the user. Use error handling if file cannot be found*/
    file = fopen(fileName, "r"); /* Open the file specified by the user in 'read' mode*/
    if(file == NULL)
    {
        perror("The following error occurred: ");
        printf("Value of errno: %d\n", errno);
    }
    else
    {
        printf("File loaded. "); /* Display a message to let the user know
                                  * that the file has been loaded properly */
    }

    while(fgets(line, 100, file)!="\n")
    {
    }
    
    return 0;
    return (printf);
}

1)I want a menu for exemple :[l]oad – [s]ave, when I write "L" then I go to :

printf("Enter the name of the file containing ship information: ");
  1. and I need a help with how to make a print to the txt file and how I can save it again with Another name I mean I choose the name .
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T18:37:38+00:00Added an answer on June 18, 2026 at 6:37 pm

    From your question 1 i.e. menu,
    1)I want a menu for exemple :[l]oad – [s]ave, when I write “L” then I go to :

    printf(“Enter the name of the file containing ship information: “);

    For this part,
    char inpChar;

    do {
        printf("enter menu: [l]oad - [s]ave\n");
        scanf("%c", &inpChar);
    } while((inpChar != 'l') && (inpChar != 'L') && (inpChar != 's') && (inpChar != 'S'));
    
    if((inpChar == '1') || (inpChar == 'L'))
    {
         printf("Enter the name of the file containing ship information: ");
         scanf("%s", filename);
    }
    

    For Q2 of printing to file,

    file = fopen(filename, "a");
    fprintf(file, "%s", line);
    fclose(file);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need some regular expressions help. So far I have my code working to allow
First of all, here is the basic code for the site I need help
Hey, I need som help to list my added dates from database, and split
Need a little help with string formatting... I have a string like this: Bmw
I haven't use PHP for some time, and I need some help to create
We need to tell the outcome of the following C program: main() { int
Need to apply a filter to a file like this: TUPAC_0006:1:1:2554:2356#0/1 0 * 0
Need a map reduce function by mongo in php This my mongo structure [_id]
Need help, function getFamily() { FB.api('/me/family', function(response) { alert(JSON.stringify(response)); }); } With the above
Need just a push in the right direction with this. I'm building a multi-language

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.