Question

Question 23 Not yet answered Write an algorithm that reads a file of studentsNames. We want to determine whether or not the n
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Algorithm:

1. Start

2. open the file studentsNames in read mode.

3. parse through the file line by line and compare it to the name

4. if the name is found print "the name is found" else print "not found".

5. close the file.

6. Stop

Name.c:

#include<stdio.h>
#include<string.h>
int main(int argc, char * argv[]) {
FILE * fp;
int flag = 0;
int i=0;
char * line = NULL;
ssize_t read;
size_t len = 0;
char *name = "Adam Brown";
fp = fopen("studentsNames", "r");
if (fp == NULL) {
printf("Could not open file\n");
return -1;
}
while ((read = getline( & line, & len, fp)) != -1) {
i=0;
while(line[i] != '\0')
   {
       if(line[i] == '\n')
       {
           line[i] = '\0';
        }
        i++;
   }
if(strcmp(line,name)==0) {
flag = 1;
printf("The name Adam Brown is in the file\n");
break;
}
}

  fclose(fp);
if(flag == 0)
printf("error: Adam Brown not found\n");
return 0;

}

Output:

shyam@shyam: -/Desktop/Chegg/ shyam@shyam:-/Desktop/Chegg/c$ cat studentNames Vishnu Prasad Tom Cruise Adam Brown shyam@shyam

Add a comment
Know the answer?
Add Answer to:
Question 23 Not yet answered Write an algorithm that reads a file of studentsNames. We want...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 23 Not yet answered Marked out of 1 Flag question Indicate the different stages of...

    Question 23 Not yet answered Marked out of 1 Flag question Indicate the different stages of the growth curve in a batch system by dragging the words to the corresponding location on the curve. Drag and drop from the answers below. Stationary phase Time (hr) Exponential phase Lag phase Death phase

  • Question 21 Which of the following statements are true concerning free credit balances? Not yet answered...

    Question 21 Which of the following statements are true concerning free credit balances? Not yet answered Marked out of 1.00 Flag question Select one: a. These funds are called excess margin. o b. Dealer members cannot use these funds, as they belong to their clients. O c. If these funds are used, they must be replaced in the client's account within 24 hours. o d. Dealer members can use these monies in their day-to-day business activities. Question 22 Louise short-sold...

  • Question 21 What are the results of the physical count are compared to? Not yet answered...

    Question 21 What are the results of the physical count are compared to? Not yet answered Marked out of 1.00 Select one: a. last year's count P Flag question O b. the computer (or book) count c. balance sheet value O d. last quarter's count Question 22 Not yet answered How is a formal promissory note in acknowledgment of a customer's debt classified? Marked out of 1.00 Select one: O a. as a note receivable Flag question O b. as...

  • Question 23 Not yet answered Imagine that you repeat the Hershey and Chase experiment but use...

    Question 23 Not yet answered Imagine that you repeat the Hershey and Chase experiment but use radioactive Carbon instead of Sulfur or Phosphorous. What statements below will be true for this experimental setting? Points out of 2.50 P Flag question Select one: a. None of the listed statements are appropriate conclusions for this experimental setting O b. The radioactive carbon would NOT be found neither in the supernatant or the bacterial pellet O c. The macromolecule responsible of genetic transmission...

  • Not yet answered Marked out of 1.00 Flag question Question text What is the value of...

    Not yet answered Marked out of 1.00 Flag question Question text What is the value of the following Python expression? not(True and False) Select one: True False Question 2 Not yet answered Marked out of 1.00 Flag question Question text Consider the following Python program. fin = open('words.txt') for line in fin: word = line.strip() print(word) What does the program loop over? Select one: a. Lines in a file b. Lines in a list c. Words in a dictionary d....

  • Write a program that reads a file containing an arbitrary number of text integers that are...

    Write a program that reads a file containing an arbitrary number of text integers that are in the range 0 to 99 and counts how many fall into each of eleven ranges. The ranges are 0-9, 10-19, 20-29,..., 90-99 and an eleventh range for "out of range." Each range will correspond to a cell of an array of ints. Find the correct cell for each input integer using integer division. After reading in the file and counting the integers, write...

  • Question 18 Not yet answered Marked out of 10.00 Flag question Each spring the buzzards return...

    Question 18 Not yet answered Marked out of 10.00 Flag question Each spring the buzzards return to Hinkley, Ohio from their wintering grounds in Mexico (this is absolutely true, you can Google it). Remarkably, they make their migration in one continuous flight over about 72 hours, through day and night without a pause. You want to know how they manage to find their way at night and get the clever idea of gluing magnets on the heads of several buzzards...

  • Question 18 Not yet answered Marked out of 10.00 Flag question Each spring the buzzards return...

    Question 18 Not yet answered Marked out of 10.00 Flag question Each spring the buzzards return to Hinkley, Ohio from their wintering grounds in Mexico (this is absolutely true, you can Google it). Remarkably, they make their migration in one continuous flight over about 72 hours, through day and night without a pause. You want to know how they manage to find their way at night and get the clever idea of gluing magnets on the heads of several buzzards...

  • Question 1: Write a program in C that reads a date from the keyboard and tests...

    Question 1: Write a program in C that reads a date from the keyboard and tests whether it contains a valid date. Display the date and a message that indicates whether it is valid. If it is not valid, also display a message explaining why it is not valid. The input date will have the format: mm/dd/yyyy Note that there is no space in the above format. A date in this format must be entered in one line. A valid...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT