C 指针错误。一元数的类型参数无效*
下面是我为调试指针而编写的标题C 指针错误。一元数的类型参数无效*,c,pointers,memset,C,Pointers,Memset,下面是我为调试指针而编写的标题 #include "cdebug.h" #include "stdlib.h" int main() { char *cbloc = (char *)malloc(sizeof(char) * 40); memset(cbloc, 40, sizeof(char) * 40); DFORC(cbloc, 0, sizeof(char) * 40); system("PAUSE"); } \ifndef\CDEBUG\H_
#include "cdebug.h"
#include "stdlib.h"
int main()
{
char *cbloc = (char *)malloc(sizeof(char) * 40);
memset(cbloc, 40, sizeof(char) * 40);
DFORC(cbloc, 0, sizeof(char) * 40);
system("PAUSE");
}
\ifndef\CDEBUG\H_
#定义_
#包括“stdio.h”
整数计数器;
//skrillac编写的调试函数
//常数
#定义NEWLN()printf(“\n”);
#为(计数器=偏移量;计数器
该错误发生在DFORC()宏中的某个位置。我想我的问题是,它到底在哪里?我该如何修复它?
cbloc
是指向字符的指针,因此在DFORC
中,ptr
也是指向字符的指针。声明:
#ifndef _CDEBUG_H_
#define _CDEBUG_H_
#include "stdio.h"
int counter;
//Debugging functions written by skrillac
//constants
#define NEWLN() printf("\n");
#define DFORC(ptr, offset, len) for (counter = offset; counter < len+offset; counter++)printf("'%c', ", *ptr[counter]);
#define DFORI(ptr, offset, len) for (counter = offset; counter < len+offset; counter++)printf("'%i', ", *ptr[counter]);
#define DFORV(ptr, offset, len) for (counter = offset; counter < len+offset; counter++)printf("%x, ", *ptr[counter]);
#endif
首先使用ptr
作为数组,访问该数组的元素计数器
。这将返回一个char
(notachar*
)。然后尝试取消引用该char
,这是没有意义的,因此会出现错误
要解决此问题,请将该语句更改为以下任一语句:
printf("'%c', ", *ptr[counter]);
printf("'%c', ", ptr[counter]);
printf("'%c', ", *(ptr + counter));