linux - 如何在使用夹板工具检查源代码时包含头文件?

标签 linux parsing splint

我创建了 2 个 C 程序源代码文件和一个仅包含函数声明的头文件。

mypattern.h

 #include<stdio.h>
void pattern_check(char *,int,char *);

pattern_main.c
    #include<mypattern.h>
int main(int argc,char *argv[])
{
 int i,max,flag=1;
 char *p,*cmd="end";
 if(argc!=3)
 {
  printf("usage : Invalid no of arguments\n");
  return 0;
 }
 max=atoi(argv[1]);
 char elements[max][15];
 printf("\nEnter the %d input strings :\n",max);
 for(i=0;i<max;i++)
 {
   p=elements[i];
  // printf("%u\n",p);
   scanf("%s",p);
//   printf("%s-->%u\n",p,p);
  if(*p==*cmd)
  {
   flag=0;
   max=i;
   break;
  }
 }
 if(flag)
 p=p-(sizeof(char)*((max-1)*15));
 else
 p=p-(sizeof(char)*((max)*15));
 pattern_check(p,max,argv[2]);
 return 0;
}

pattern_search.c
  #include<mypattern.h>
void pattern_check(char *elements,int max,char *pattern)
{
 int i,count=0,len=0;
 char *ptr,*ch,*pat[max],*output=NULL;
// printf("\nPattern : %s\n",pattern);
 for(i=0;i<max;i++)
 {
 // printf("\nfor loop %d\n",i);
  ptr=elements+(i*15);
  //printf("%u-->%s\n",ptr,ptr);
  ch=strstr(ptr,pattern);
  if(ch!=NULL)
  {
   pat[count]=(char *)malloc(sizeof(char));
   if(pat[count]==NULL)
   {
    printf("\nMalloc failed\n");
    return;
   }
   strcpy(pat[count],ptr);
  // printf("\nCount : %d\n",count);
  // printf("\n%s-->%u\n",pat[count],pat[count]);
  count++;
  }
 }
 printf("Pattern mateched elements :\n");
 for(i=0;i<count;i++)
 {  printf("\n-->%s\n",pat[i],pat[i]);
    len+=strlen(pat[i]);
 }
// printf("\nFinal length : %d\n",len);
  output=malloc(sizeof(char)*(len+1));
  if(NULL==output)
  {
   printf("Malloc failed \n");
   return;
  }
 for(i=count-1;i>=0;i--)
  strncat(output,pat[i],strlen(pat[i]));
 printf("\nFinal concatended string output : %s\n\n",output);
 free(output);
}

在 Linux 上使用夹板工具检查此代码时,
 splint pattern_main.c

我收到以下错误:
pattern_main.c:1:22: Cannot find include file mypattern.h on search path:
                        /usr/include;/usr/include
  Preprocessing error. (Use -preproc to inhibit warning)
Preprocessing error for file: /user/gur29597/mysourcecode/Memory_pgm/pattern_main.c
*** Cannot continue.

我怎样才能使它正确?

最佳答案

#include "mypattern.h" 与双引号一起使用,而不是角度,和/或将包含一些 -I 参数的目录传递给 gcc 。并且不要忘记使用 -Wall 标志到 GCC 来获取所有警告!要了解包含哪些 header ,请使用 -H 或使用 gcc -C -E pattern_main.c 生成预处理形式

关于linux - 如何在使用夹板工具检查源代码时包含头文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8132776/

相关文章:

parsing - 使用SnakeYaml进行解析时,将忽略yaml中的字段(无法在类中找到属性)

c++ - 有没有更好的方法来解析这样的一行文本?

mysql - Splint 不知道库函数正在释放内存

c - 如何为 Splint 注释 BoehmGC 收集的代码?

linux - 共享对象可以有自己的线程在后台运行吗?

linux - Gradle 停留在配置项目

c++ - 信号系统调用可以与类的 C++ 静态成员一起使用吗?

javascript - 使用 RegExp 和 exec 在 JavaScript 中解析 XML - 它通常可以工作,但在少数情况下却不能 - 知道为什么吗?

无法摆脱夹板警告 "Field used before definition", "rvalue is used that may not be initialized to a value on some execution"

java - 通过java或linux查找ping响应接口(interface)