Question

let's say we have 2 text files called hello.txt and hello2.txt hello.txt contains... hi my name...

let's say we have 2 text files called hello.txt and hello2.txt

hello.txt contains...

hi

my

name

is

justin

and hello2.txt contains

my justin

so hello.txt conains all the words and hello2.txt containts "ranges" for hello1.txt

write a C program such that it will print all the words from hello.txt between ranges given in hello2.txt

use fscanf

so for this case it should print name is only

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

#include <stdio.h>
#include <stdlib.h> // For exit() function
int match2Strings(char a[],char b[])
{
int i;
for(i=0;a[i]!='';i++)
{
if(a[i]!=b[i])
return 0;
}
return 1;
}
int main()
{
char c[1000];
FILE *fptr;

if ((fptr = fopen("hello.txt", "r")) == NULL)
{
printf("Error! opening file");
// Program exits if file pointer returns NULL.
exit(1);
}

FILE *fptr1;

if ((fptr1 = fopen("hello2.txt", "r")) == NULL)
{
printf("Error! opening file");
// Program exits if file pointer returns NULL.
exit(1);
}
char first[100],second[100];
fscanf(fptr1,"%s", first);
fscanf(fptr1,"%s", second);
// reads text until newline
int flag=0;
while(fscanf(fptr,"%s", c)!=EOF)
{
if(strlen(c)==strlen(second)&&flag==1)
{
if(match2Strings(second,c)==1)
flag=-1;
}

if(flag==1)
printf("%s ",c);
if(strlen(c)==strlen(first)&&flag==0)
{
flag=match2Strings(first,c);
}


}

//printf("Data from the file: %s", c);
fclose(fptr);

return 0;
}

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
let's say we have 2 text files called hello.txt and hello2.txt hello.txt contains... hi my name...
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
  • In python Attached is a file called sequences.txt, it contains 3 sequences (one sequence per line)....

    In python Attached is a file called sequences.txt, it contains 3 sequences (one sequence per line). Also attached is a file called AccessionNumbers.txt. Write a program that reads in those files and produces 3 separate FATSA files. Each accession number in the AccessionNumbers.txt file corresponds to a sequence in the sequences.txt file. Remember a FASTA formatted sequence looks like this: >ABCD1234 ATGCTTTACGTCTACTGTCGTATGCTTTACGTCTACTGACTGTCGTATGCTTACGTCTACTGTCG The file name should match the accession numbers, so for 1st one it should be called ABCD1234.txt. Note:...

  • In python Attached is a file called sequences.txt, it contains 3 sequences (one sequence per line)....

    In python Attached is a file called sequences.txt, it contains 3 sequences (one sequence per line). Also attached is a file called AccessionNumbers.txt. Write a program that reads in those files and produces 3 separate FATSA files. Each accession number in the AccessionNumbers.txt file corresponds to a sequence in the sequences.txt file. Remember a FASTA formatted sequence looks like this: >ABCD1234 ATGCTTTACGTCTACTGTCGTATGCTTTACGTCTACTGACTGTCGTATGCTTACGTCTACTGTCG The file name should match the accession numbers, so for 1st one it should be called ABCD1234.txt. Note:...

  • I need help writing this C code. Here is the description: Let's say we have a...

    I need help writing this C code. Here is the description: Let's say we have a program called smart typing which does two things: The first letter of a word is always input manually by a keystroke. When a sequence of n letters has been typed: c1c2...cn and the set of words in the dictionary that start with that sequence also have c1c2...cnc then the smart typing displays c automatically. we would like to know,  for each word in the dictionary,...

  • Homework IX-a Write a program that opens a text file, whose name you enter at the keyboard You wi...

    Homework IX-a Write a program that opens a text file, whose name you enter at the keyboard You will be using the file text.txt to test your program. Print out all of the individual, unique words contained in the file, in alphabetical order Print out the number of unique words appearing in text.txt. Call your program: YourName-HwrklXa.py Make sure that your name appears as a comment at the beginning of the program as well as on the output display showing...

  • Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The progra...

    Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs opening any of the 3 For example, (user input shown in caps in first line) Enter first...

  • There is a file called mat2.txt in our files area under the Assignments folder. Download it...

    There is a file called mat2.txt in our files area under the Assignments folder. Download it and save it in the same folder where this Matlab file (HW08_02.m) is saved. It may be worth opening that text file to see how it is set out. Note well, however, that the file might have a different number of lines and different number of numbers on each line. Write a Matlab program that does the following: Prompt the user for an input...

  • Python Help Please! This is a problem that I have been stuck on.I am only suppose...

    Python Help Please! This is a problem that I have been stuck on.I am only suppose to use the basic python coding principles, including for loops, if statements, elif statements, lists, counters, functions, nested statements, .read, .write, while, local variables or global variables, etc. Thank you! I am using python 3.4.1. ***( The bottom photo is a continuation of the first one)**** Problem statement For this program, you are to design and implement text search engine, similar to the one...

  • #A common problem in academic settings is plagiarism #detection. Fortunately, software can make t...

    #A common problem in academic settings is plagiarism #detection. Fortunately, software can make this pretty easy! # #In this problem, you'll be given two files with text in #them. Write a function called check_plagiarism with two #parameters, each representing a filename. The function #should find if there are any instances of 5 or more #consecutive words appearing in both files. If there are, #return the longest such string of words (in terms of number #of words, not length of the...

  • #A common problem in academic settings is plagiarism #detection. Fortunately, software can make this pretty easy!...

    #A common problem in academic settings is plagiarism #detection. Fortunately, software can make this pretty easy! # #In this problem, you'll be given two files with text in #them. Write a function called check_plagiarism with two #parameters, each representing a filename. The function #should find if there are any instances of 5 or more #consecutive words appearing in both files. If there are, #return the longest such string of words (in terms of number #of words, not length of the...

  • Hi I would like to revise the codes below to bring all text files I have...

    Hi I would like to revise the codes below to bring all text files I have text file 0 from 10 I will give you link here https://drive.google.com/open?id=1LnWqv8ftzARx5Rhf7HtVlVkLVlcA1FtI when tokenizer read all tokens from the 10 files which attached above, I would like to arrange it in alphabetical order and want to make same word tokens being merged. For instance, You are my son? You are my son and good friend! you are the only one whom I loved. The...

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