Question: You are required to write a C program - whose input is an existing text file with a name specified in a command line as
You are required to write a C program
- whose input is an existing text file with a name specified in a command line as the first argument,
- whose output is a new text file with a name specified in a command line as the second argument; requirements to the new text file are given below.
Input and output files should have extension .txt but only names of the files are specified in a command line.
Example: suppose the executable version of your program is named p2.out. The program will be executed by a command line of the following form:
p2.out inputfile outputfile
In this case file inputfile.txt must exist, outputfile.txt will be created.
Requirements for the output text file:
The output file should have copy of each line of the input file in the same order of lines. Each line of the output file should consist of the same words as the corresponding line in the input file but ordered backward.
In the input file words are separated by one or more spaces (' ') or by horizontal tab ('\t'). In the output file words should be separated by single space.
In the input and output files, each line ends with new line character ( ). Lines do not exceed 255 characters including new line character.
The outline of your C program is as follows.
1.Read command line arguments and check the correctness.
2.Create a new file named second argument + ".txt"
3.Proceed with converting input file lines into output file lines.
4.Stop and print out "Finished." once finish reading and writing the files.
Thus, each time your program is executed, it should handle just one input file.
Sample input file:
char * strtok ( char * str, const char * delimiters ); Split string into tokens A sequence of calls to this function split str into tokens which are sequences of contiguous characters separated by any of the characters that are part of delimiters. On a first call, the function expects a C string as argument for str , whose first character is used as the starting location to scan for tokens. In subsequent calls ,the function expects a null pointer and uses the position right after the end ofthe last token as the new starting location for scanning.
Sample output file:
); delimiters * char const str, * char ( strtok * char tokens into string Split tokens into str split function this to calls of sequence A characters contiguous of sequences are which delimiters. of part are that characters the of any by separated string C a expects function the call, first a On the as used is character first whose , str for argument as tokens. for scan to location starting pointer null a expects function ,the calls subsequent In ofthe end the after right position the uses and scanning. for location starting new the as token last
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
