Thread: How to extract a entire line based on one keyword in a File

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    1

    Lightbulb How to extract a entire line based on one keyword in a File

    hi experts,

    Good day to you all..

    Will you please help me on the below problem, ( program needs to be in C language only)

    I have file which contains data like below:

    File.txt:

    Hello welcome to world
    c file programming with files


    Need: I have a file which looks like the above one with multiple lines and each word is seperated by a space. I want to input a keyword to the program it has to search the file and retrieve the entire line whereever the key word occurs in the given file.

    Eg: input: programming
    output: c file programming with files (2nd line in the file)

    please help to proceed in my academic project..

    Thanks in Advance,
    coolpad

  2. #2
    Registered User
    Join Date
    Nov 2011
    Location
    Buea, Cameroon
    Posts
    197
    well you create a search string function with that opens the file stream searches for the word using strcmp and after every '\n' character it incrementes a variable and when it finds the word, it returns the number of '\n' counted which corresponds to the line in which the function is found in special fprintf statement. so you do the logic and it'll be fine...

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    please help to proceed in my academic project
    C Tutorial - Learn C - Cprogramming.com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Conditional if based on command line arguments problem
    By DimensionX in forum C Programming
    Replies: 4
    Last Post: 11-05-2009, 04:38 AM
  2. C++: Output An Entire Text File- Can It Be Done?
    By lusciousleanne in forum C++ Programming
    Replies: 6
    Last Post: 01-30-2008, 09:27 AM
  3. reading entire file into a class
    By linucksrox in forum C++ Programming
    Replies: 2
    Last Post: 12-12-2005, 10:52 AM
  4. entire file
    By linuxdude in forum C Programming
    Replies: 30
    Last Post: 02-23-2004, 06:06 PM
  5. command line argument to accept entire directory
    By westm2000 in forum C Programming
    Replies: 2
    Last Post: 04-02-2002, 10:12 PM

Tags for this Thread