正在加载图片...
-10- Problem 7-C programming (15 points) Write a function void UntabifyFile(FILE *infile,FILE *outfile); which copies the entire contents of the input file to the output file,replacing any tabs in the input with enough spaces to reach the next tab stop,which are traditionally set at every eight spaces,as they were in MiniSim code.For flexibility,your version of untabifyFile must use the value of the constant rabstops to control the size of a tab stop.For MiniSim files,rabstops would be set as follows: #define TabStops 8 For Thetis programs,the value of rabstops would be changed to 4. Suppose,for example,that the input file contains the following lines,where the arrow symbol (→)represents a tab: start:◆INPUT◆x →OUTPUT◆x →HALT x:◆0 When you read in a line from the file,you need to go through that line character by character, looking for instances of the tab character,which is denoted in C as '\t'.When you find one. you need to replace it in the output by a sequence of spaces.The number of spaces is determined by figuring out how many characters you need to reach the next tab stop.If rabstops has the value 8,you need to add spaces until you reach the next column position divisible by 8. As an example,the first line in the input file is start:→input-x The s,t,a,r,t,and characters take up positions 1,2,3,4,5,and 6 on the line.The tab character that follows therefore corresponds to two spaces,because 8 is the next column divisible by 8.The characters I,N,P,U,and r take up positions 9,10,11,12,and 13.At this point the tab character requires three spaces to reach the next tab stop at 16. The completed output file looks like this,where the space character is indicated by the symbol-. start:-inputx halt x:0 Remember that you have to write only the untabifyFile procedure and not the surrounding main program.The main program takes care of opening and closing the files;your job is simply to copy data from the input file to the output file,replacing tabs with spaces as you go.– 10 – Problem 7—C programming (15 points) Write a function void UntabifyFile(FILE *infile, FILE *outfile); which copies the entire contents of the input file to the output file, replacing any tabs in the input with enough spaces to reach the next tab stop, which are traditionally set at every eight spaces, as they were in MiniSim code. For flexibility, your version of UntabifyFile must use the value of the constant TabStops to control the size of a tab stop. For MiniSim files, TabStops would be set as follows: #define TabStops 8 For Thetis programs, the value of TabStops would be changed to 4. Suppose, for example, that the input file contains the following lines, where the arrow symbol ( ) represents a tab: start: INPUT x OUTPUT x HALT x: 0 When you read in a line from the file, you need to go through that line character by character, looking for instances of the tab character, which is denoted in C as '\t'. When you find one, you need to replace it in the output by a sequence of spaces. The number of spaces is determined by figuring out how many characters you need to reach the next tab stop. If TabStops has the value 8, you need to add spaces until you reach the next column position divisible by 8. As an example, the first line in the input file is start: input x The s, t, a, r, t, and : characters take up positions 1, 2, 3, 4, 5, and 6 on the line. The tab character that follows therefore corresponds to two spaces, because 8 is the next column divisible by 8. The characters I, N, P, U, and T take up positions 9, 10, 11, 12, and 13. At this point the tab character requires three spaces to reach the next tab stop at 16. The completed output file looks like this, where the space character is indicated by the symbol . start: input x output x halt x: 0 Remember that you have to write only the UntabifyFile procedure and not the surrounding main program. The main program takes care of opening and closing the files; your job is simply to copy data from the input file to the output file, replacing tabs with spaces as you go
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有