Write a function named read_line

Assignment Help C/C++ Programming
Reference no: EM13713074

Answer the following questions and also justify your answers with appropriate examples

Question- 1 Write a function named 'read_line' which has one input parameter ('specs') and one output parameter ('ret_line'). Your function should do the following:

Question- 2 Suppose 'specs' is a struct with 4 fields: {file_dir, file_name, nlines, my_line}. Use if?end or if?elseif?end statements to check that:

Part a- 'specs'isindeedastruct.

Part b- Thefourfieldsaboveallexist.

Part c- Thefields'file_dir','file_name'are(non?empty)strings

Question-3 You should use the 'error' function to indicate an error if your checks above fail.

Question-4 Now supposes you have a directory whose name is stored in 'specs.file_dir' which contains a file whose name is stored in 'specs.file_name'.

You should suppose that you have a simple text file which contains text (NOT numeric data).

Question-5 Your function should open the file (hint: use fopen), and read 'specs.nlines' number of lines (rows) from the file into a cell array 'C'. Each element of C should have one line from your file.

You can suppose that there are no errors in the parameter 'specs.nlines', that is, it can't exceed the number of lines in your file.

Question-6 Suppose 'specs.my_line' specifies some line number. The output parameter 'ret_line' should be set to this line (you should return a string).

Question-7 Verify that your code works by saving some text into a file (created in notepad / textedit) and saving the file with extension '.txt'. You should attach the file (call it 'test.txt') with your code.

Could you show me how to write a proper code for this problem and how to complete it. Thanks

Reference no: EM13713074

Questions Cloud

Prepare a general set of instructions : Prepare a general set of instructions that will allow us to change any displayed value (from 0 to 9) to any desired value (from 0 to 9) in the least number of steps.
Implement a class student : Implement a class Student. For the purpose of this exercise, a student has a name and a total quiz score. Supply a suitable constructor and methods getName( ), addQuiz(int score), getTotalScore( ), and getAverageScore ( ).
Write a flowchart to solve any linear equation : Write a flowchart to solve any linear equation ax+b=0 -
Find how much heat per cycle does the engine absorb : How much work does this engine do each cycle.How much heat per cycle does this engine absorb at the hot reservoir?
Write a function named read_line : supposes you have a directory whose name is stored in 'specs.file_dir' which contains a file whose name is stored in 'specs.file_name'.
What should be the banking angle of the curve : What should be the banking angle of the curve so that the force of the pavement on the tires of the car is in the normal direction? Answer in units of degrees.
What is the average friction on the ball : a 200 g plastic ball is at rest on a frictionless incline 0.658 m above the surface of a table. The ball then rolls down the incline and across the table coming to rest after a distance of 2.45 m.
Determine how far apart are mars and phobos : Mars has a mass of about 6.77×1023kg, and its moon Phobos has a mass of about 9.6×1015kg. If the magnitude of the gravitational force between the two bodies is 4.58×1015N.
Write an unambiguous grammar : Write an unambiguous grammar for the given languages- You have to prepare unambiguous grammar for the above languages. Please help! I am stuck on this question

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Write a program to calculate the volume flow rate

Write a program to calculate the volume flow rate in cubic feet per second of water flowing through a pipe of diameter d in inches and a velocity of v feet per second.

  Create an output array using input

create an output array using input x values 1 through 10.

  The manager of a football stadium

The manager of a football stadium wants you to write a program that calculates the total ticket sales after each game. There are four types of tickets-box, sideline, premium and general admission. The data is stored in a file, tickets.txt, in the fol..

  Create a two-dimensional array

Describe a problem where you might need to create a two-dimensional array to accurately model the data, and describe how you would use the data to help solve the problem.

  Write a program in which the program prints out

Use (switch statement) to write a program in which the program prints out the input (single character) if the character is not '2','t', or 'w'. Use 'default' and 'break' wisely.

  Write a switch-case programming for calculation

How to use C++ to write a switch-case programming for calculation? Test the program for a wide range of possible inputs including division by zero and square root of negative values.

  What''s a more efficient way to write

What's a more efficient way to write this function for a matrix? This one has to go through all the numbers, but that would take too long. r_num is row and c_num is column

  Write a c program that asks for and reads in two integers

Write a C program that asks for and reads in two integers and then reports if one is a multiple of the other.

  In this program you will implement a simple reverse polish

in this program you will implement a simple reverse polish notation rpn calculator. rpn is a notation in which

  Write a test program that creates an account object

Write a test program that creates an Account object with an ID of 1122, a balance of 20000USD, and an annual interest rate of 4.5% - Use the withdraw method to withdraw 2.500USD, use the deposit method to deposit 3000USD and print the balance, mont..

  Determine the reynolds number of flow in a rectangular

determine the reynolds number of flow in a rectangular channel 2m deep and 4m wide if the water level is 60 and running

  Child process to take the role of the number guesser

Write a program in C that takes a number between 1 and 1024 as input on the command line, and then forks a child process to take the role of the number guesser

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd