- 论坛徽章:
- 0
|
回复 4# ljmmail
你好,感谢解答。如图,我的问题是找到Indexes所在的<Directory “/var/www/html”> Indexes </Directory>
我现在能找到Indexes,但是不知道怎么输出/var/www/html ? 求教!
我的想法是,把<Directory “/var/www/html”>视作一个整体,在读到</Directory>之前,匹配Indexes,如果有,则输出<Directory “/var/www/html”>。。 但是代码一直有问题。能否帮忙具体到代码解答一下?谢谢。
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main()
- {
- char acBuf[1024]; //定义一个字符数组
- char * pWord = "Indexes";
- char acOut[10] = {0};
- char *p;
- char strDir[100] = {0};
- char *pDir = "<Directory>";
- FILE *fp = fopen("httpd.conf", "r"); //定义一个文件指针,打开指定文件
- if( fp == NULL) {
- printf("openfile failed.\n");
- return -1;
- }
- memset(acBuf, 0, 1024); //初始化acbuf
- memset(strDir, 0, sizeof(strDir));
- while(fgets(strDir, 100, fp) != NULL)
- {
- if( pDir != NULL) {
- // while( fgets(acBuf, 1024, fp) != NULL) {
- p = strstr(acBuf, pDir); //取出目录所在行
- if( p == NULL) {
- // printf("error.\n");
- } else {
- strcpy(strDir, acBuf);
- continue;
- }
- p = strstr(acBuf, pWord);
- if( acBuf[0] == '#' || p == NULL)
- {
- } else {
- printf(strDir);
- }
- // }
- }
- }
- fclose(fp);
- return 0;
- }
复制代码
|
|