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: ");
- 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 .
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;
For Q2 of printing to file,