2011-06-10 56 views

回答

0

這是你的功課?如果是這樣的話,你應該真的自己做這個......你將如何學習?您還應該提供您在發佈問題時已完成的工作。

這是一個非常簡單的解決方案。

#include <stdio.h> 
#include <string.h> 

#define SIZE_OF_BUFFER 255 
#define FILENAME "yourpage.html" 
#define TRUE 1 
#define FALSE 0 

/* Read the contents of the (first) BODY tag into buffer */ 
int main(void) 
{ 
    int next_read = FALSE; 
    char buffer[SIZE_OF_BUFFER] = {'\0'}; 
    FILE *htmlpage; 

    htmlpage = fopen(FILENAME, "r"); 
    if(htmlpage == NULL) 
    { 
     printf("Couldn't locate file - exiting..."); 
     return -1; 
    } 

    while(fscanf(htmlpage, " %[^\n]s", buffer) != EOF) 
    { 
     if(strncmp(buffer, "<BODY>", 6) == 0) 
     { 
      next_read = TRUE; 
     } 
     else if(next_read == TRUE) 
     { 
      break; 
     } 
    } 

    fclose(htmlpage); 

    if(next_read == TRUE) 
    { 
     /* print the contents of buffer */ 
     printf("%s\n", buffer); 
    } 
    else 
    { 
     printf("No <BODY> tag found in file!\n"); 
    } 

    return 0; 
} 
相關問題