Thread: Reading HTML files

  1. #1
    Registered User
    Join Date
    Nov 2017
    Posts
    9

    Reading HTML files

    • Write a program that reads in an input text file and differentiates between C source files (typically include a #include directive towards the beginning and are case sensitive), HTML files (typically include the case-insensitive <html> and </html> tags towards the beginning and end respectively), and ‘other type’ of files. The program is permitted a margin of imprecision.


      Im aware to the point on how to call a text file and how to open an HTML file, but how do I "differentiate" between the files? Your help would be appreciated



      FILE *fp;
      fp = fopen("test.txt", "w+");
      fprintf(fp, "bla bla bla...\n");
      fputs("This is testing for fputs...\n", fp);
      fclose(fp);



  2. #2
    Registered User
    Join Date
    Jun 2017
    Posts
    157
    One way is to read the file line by line - using fgets.
    If a line contains <html> it's a html site,
    if it contains #include then it it a C or C++ file
    otherwise it's other type.
    If a line contains a substring use strstr

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. reading data from html page
    By cnu_sree in forum C Programming
    Replies: 7
    Last Post: 11-01-2007, 11:22 AM
  2. Parsing HTML files
    By slcjoey in forum C++ Programming
    Replies: 2
    Last Post: 08-28-2005, 07:01 AM
  3. Reading HTML files and Images from Website
    By Fade_to_Blah in forum C Programming
    Replies: 5
    Last Post: 07-08-2005, 08:49 AM
  4. HTML files
    By Granger9 in forum C Programming
    Replies: 3
    Last Post: 08-21-2002, 11:14 PM
  5. Downloading HTML Files from Web Page
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 07-18-2002, 05:59 AM

Tags for this Thread