Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
3. Task 2: Reading lines from a File
Write C code which will read a line of characters (terminated by a \n) from input_file into a character array called buffer. NULL terminate the buffer upon reading a \n.
NOTE:
Your source code must display any of the given sample output below.
It means your source code should be flexible enough to meet any of the given sample output.
Your source code output must be identical to any of the given sample output.
It means you have to strictly follow what are the displayed text, labels, casing of characters in the sample output.
Strictly follow the naming of file.
Your source code must display any of the given sample output below.
It means your source code should be flexible enough to meet any of the given sample output.
Your source code output must be identical to any of the given sample output.
It means you have to strictly follow what are the displayed text, labels, casing of characters in the sample output.
Strictly follow the naming of file.
Sample OUTPUT1: |
---|
Enter File Name: lupang_hinirang.txt |
Bayang magiliw |
Perlas ng silanganan |
Alab ng puso sa dibdib mo’y buhay |
Lupang Hinirang, duyan ka ng magiting |
Sa manlulupig, di ka pasisiil |
Sa dagat at bundok na simoy |
At sa langit mong bughaw |
Tagumpay na nagnininging |
Ang bituin at araw niyan |
Kailan pa ma’y di magdidilim |
Lupa ng araw ng luwalhati’t pagsinta |
Buhay ay langit sa piling mo |
Aming ligaya nang pag may mang-aapi |
Ang mamatay ng dahil sa iyo |
Sample OUTPUT2: |
---|
Enter File Name: panatang_makabayan.txt |
Iniibig ko ang Pilipinas, |
aking lupang sinilangan, |
tahanan ng aking lahi; |
kinukupkop ako at tinutulungang |
maging malakas, masipag at marangal. |
Dahil mahal ko ang Pilipinas, |
diringgin ko ang payo |
ng aking magulang, |
susundin ko ang tuntunin ng paaralan, |
tutuparin ko ang tungkulin |
ng mamamayang makabayan: |
naglilingkod, nag-aaral at nagdarasal |
nang buong katapatan. |
Iaalay ko ang aking buhay, |
pangarap, pagsisikap |
sa bansang Pilipinas. |
Sample OUTPUT3: |
---|
Enter File Name: lupang_makabayan.txt |
The file can’t be open. File does not exists. |
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 2 images
Knowledge Booster
Similar questions
- 13. Write function quote() that takes as input the name of a file (as a string) and anindex i (as an integer). The file will contain quotes, one per line. The function shouldopen the file, read the file, close the file, and return the i-th quote (i.e. the i-th line in thefile), assuming that the quote numbering starts at 0. Test your solution onfile Wilde_Quotes.txt.>>> quote("Wilde_Quotes.txt", 5)'At twilight, nature is not without loveliness, thoughperhaps its chief use is to illustrate quotations from thepoets.\n'>>> quote("Wilde_Quotes.txt", 0)'A little sincerity is a dangerous thing, and a great dealof it is absolutely fatal.\n'>>> quote("Wilde_Quotes.txt", 23)'Patriotism is the virtue of the vicious. \n'>>>arrow_forwardPlz solve assignment 5 by using assignment 8, use c programming and plz don't use any other libraries other than stdio . harrow_forwardCreate a file main.f95, inside the file create a program arrP.You have to create a 2-D array of size 3*3 in which each element is twice of the sum of the index of its row and column. Display the array in the output which each element of the array in single line.arrow_forward
- Jupyter Notebook Fixed Income - Certicificate of Deposit (CD) - Compound Interest Schedule An interest-at-maturity CD earns interest at a compounding frequency, and pays principal plus all earned interest at maturity. Write a function, called CompoundInterestSchedule, that creates and returns a pandas DataFrame, where each row has: time (in years, an integer starting at 1), starting balance, interest earned, and ending balance, for an investment earning compoundedinterest. Use a for(or while) loop to create this table. The equation for theith year's ending balance is given by: Ei =Bi (1+r/f)f where: Ei is year i's ending balance Bi is year i's beginning balance (note: B1 is the amount of the initial investment (principal) r is the annual rate of interest (in decimal, e.g., 5% is .05) f is the number of times the interest rate compounds (times per year) The interest earned for a given year is Ei - Bi Note the term of the investment (in years) is not in the above equation; it is used…arrow_forwardYou have to read a file with 10 integers into an array named read_arr. Assume the file has been associated with the ifstream fin and num is a variable of integer data type. What will work? Group of answer choices (a) for(int i=0;i<10;++i) read_arr[i]=(fin>>num); (b) for(int i=0;i<10;++i) { fin>>num; read_arr[i]=num; } (c) int i=0; while(fin>>num) { read_arr[i]=num; ++i; } Both (b) and (c) ===================== Which of the following is a correct struct declaration? Group of answer choices None of these struct Data { int id; float price; } Data struct { int id; float price; } struct { int id; float price; } Data ====================== Consider the following code fragment. struct Employer{ string name; double salary;};void update (Employer emp){ emp.salary += 1000.00;}; int main(){ Employer e; e.name = "Test"; e.salary = 1000; update(e); cout << e.salary; return 0;}…arrow_forwardDebug the following phython code. """This function reads in data from the file specified by filename. This data is read line by line and unpacked into a single variable called data. argumentsfilename - the name of the file to be read returnsdata - a list of data, each element is a list that corresponds to the set of entries separated by commas in the original file. To access the first entry use data[0]. If x = data[0], then x[0], through x[3] will correspond to entries in the file that are read in. """ def read_file(filename):fin = open(filename,'r')line = fin.readline()data = []while line:data.append(parse_line(line))line = fin.readline()return dataarrow_forward
- pls code in pythonplagiarism: This Boolean function takes two filenames. If any line occurs in both files, return True.If not, return False. I suggest using nested loops. With nested loops, we call the loop that is in thebody of the other loop, the "inner loop". The loop that contains the inner loop is the "outer loop". Openthe second file inside the outer loop:for line1 in file1:file2 = open(fname2)for line2 in file2:Python only lets you read the file once per open, so you need this order of instructions. Make sure yourreturn False is outside of both loops. Otherwise, you will only compare the first two lines of thefiles. Make sure you close the file that gets read repeatedly after the inner loop but still inside the outerloop.Here is some (more complete) pseudocode to get you started:open file 1for line1 in file 1open file 2for line2 in file 2:if line1 == line2:return Trueclose file 2return Falsearrow_forwardWrite a C code to take input from an input .txt file and write into an output file. The input file should have int type values and the output file should contain the square of each inputfrom the input file. Must use file type pointers implementation. A sample input and output are given as follows:Input:1 2 3 4 5Output:1 4 9 16 25arrow_forward6. Write a program that will randomly generate 500 integer numbers in the range -249 to 250. Write thosenumbers in a text file named “in.txt”. Now Sort (in ascending order) all the integer numbers in the file “in.txt”using Buuble Sort. Save the sorted output into another text file named “out.txt”. (Try to write separatefunction for SWAP and BUBBLE_SORT and call them from main function.)arrow_forward
- What happens if you enter a string greater than eight characters? How can a buffer overflow be avoided?arrow_forwardExample problem. You have over 500 lines of code within a file that represent people. Some people(lines) are repeated within the file. Show an example program for how to ignore the repeated people(lines) using loops. The output from your program should read, "A total of # people are in the data file ."No functions can be used to complete this, includes file.readlines.arrow_forward9b_act2. Please help me answer this in python programming.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY