关闭

C 调试代码

标签: cfuncallbackstructnullbuffer
461人阅读 评论(0) 收藏 举报
// test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<math.h>
#include<ctype.h>
#include<stdio.h>
#include <stdlib.h>


#include "FileTest.h"
//#include "FileTest.cpp"
 
typedef enum
{
MONDAY=1,
Thusday=2,
wesday=3,
Thusdday=4,
Mayday=5,
Satusday=6,
Sunday=7,
}Week_enum;

Week_enum Week;

 
Week_enum fun()
{
	return MONDAY;
}

//int i;
extern int i;

typedef struct
{
 unsigned char b[3];
}AType;



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

/*


void fun(char str[])
{
	str++;
	str[0]='6';
}

char add()
{
	printf("add\n");
	return 0;
}
char multiply()
{
	printf("multiply\n");\
	return 0;
}
typedef int (*callback)(void *value1,void *value2);

int CmpMain(void *value1,void *value2,callback fun)
{
	if (fun(value1,value2)==0)
	{
		return 0;
	}
	else
	{
		return -1;
	}
}

int CmpInt(void *value1,void *value2)
{
	if (*((int *)value1)==*((int *)value2))
	{
		printf("0");
		return 0;
	}
	else
	{
		printf("1");
		return -1;
	}
}
*/
#if 0
#define QUEUE_SIZE 3		//队列的大小

typedef struct
{
	int Queue[QUEUE_SIZE];	
	int Rd;					//读位置
	int Wr;					//写位置
}QueueType;
static QueueType tQueue;	//定义队列


int QueueIsEmpty();
int QueueIsFull();


/**
* @brief		队列初始化
* @param[in]	*pTmp:队列数据
* @param[out]	NO
* @return		NO
* @note 
*/
void QueueInit(QueueType *pTmp)
{
	memset(&tQueue,0,sizeof(QueueType));
}
/**
* @brief		从队列中读出一个元素
* @param[in]	NO
* @param[out]	*p:读出的元素
* @return		0:OK
				-1:队列已空,读取失败
* @note 
*/
int QueueRd(int *p)
{
	if (QueueIsEmpty()==-1)
	{
		
		tQueue.Rd  =(tQueue.Rd+1)%QUEUE_SIZE;//首尾相接
		*p =tQueue.Queue[tQueue.Rd];
		return 0;
	}
	else
	{
		return -1;
	}
}
/**
* @brief		向队列写入一个元素
* @param[in]	Value:写入的元素
* @param[out]	NO
* @return		0:OK
				-1:队列已满,写入失败
* @note 
*/
int QueueWr(int Value)
{
	if (QueueIsFull()==-1)
	{
		
		tQueue.Wr  =(tQueue.Wr+1)%QUEUE_SIZE;//首尾相接
		tQueue.Queue[tQueue.Wr] =Value;
		return 0;
	}
	else
	{
		return -1;
	}
}
/**
* @brief		判断队列是否是满的
* @param[in]	NO
* @param[out]	NO
* @return		0:队列已满
				-1:队列非满
* @note 
*/
int QueueIsFull()
{
	if (   ((tQueue.Rd==0) && (tQueue.Wr+1==QUEUE_SIZE))
		|| (tQueue.Rd-tQueue.Wr==1)
		)
	{
		return 0;
	}
	else
	{
		return -1;
	}
}
/**
* @brief		判断队列是否是空的
* @param[in]	NO
* @param[out]	NO
* @return		0:队列已空
				-1:队列非空
* @note 
*/
int QueueIsEmpty()
{
	if (tQueue.Rd == tQueue.Wr)
	{
		//已空
		return 0;
	}
	else
	{
		return -1;
	}
}
#endif


typedef enum
{
	A=0,
	B=1,
	C=2,
	D=3,
	E=4,
	F=5
}EgList;

typedef struct _chain
{
	int			  value;
	struct _chain *next;
}ChainType;

ChainType *Root,*Item;

int write(int tmp)
{
	ChainType *pTmp;
	
	pTmp =(ChainType *)malloc( sizeof(ChainType) );
	if (pTmp==NULL)
	{
		return -1;
	}
	else
	{
		memset(pTmp,0,sizeof(ChainType));
		if( Item==NULL )
		{
			//首个元素
			Root =pTmp;
			Item =Root;
		}
		else
		{
			Item->next =pTmp;
			Item =Item->next;
		}
		Item->value =tmp;
		return 0;
	}
}

void chain_free(ChainType *pRpotTmp)
{
	ChainType *pTmp,*pItem;
	pItem =pRpotTmp;
	while(pItem!=NULL)
	{
		pTmp =pItem->next;
		free(pItem);
		pItem =pTmp;
	}
}

#if 1
void main()
{
	
	int i;

	for (i=0;i<5;i++)
	{
		if( write(i)!=0 )
		{
			while(1);
		}
	}

	chain_free(Root);
	while(1);



#if 0
	EgList temp;
	temp  =5;

	printf("%d",temp);
#endif

#if 0
	int d=-8;
	printf("%d",d);
#endif
#if 0
	int i=0,tmp,*p;

	p =&tmp;
	QueueInit(&tQueue);

	while(1)
	{
		QueueWr(++i);
		QueueRd(p);
	}
#endif
	/*int a=10,b=2;
	CmpMain(&a,&b,CmpInt);*/

	/*char (*qw[4][4])()={add,multiply};
	(**qw)();
	(*(*qw+1))();

	char **************ppp;*/

	/*char str1[]="abcd";
	char *str2="abcd";

	int a=sizeof(str1);
	int b=sizeof(str2);

	fun(str1);

	printf("23");*/
/*
#if 0
AType a ;
AType *p=&a;
int c,d;
c =sizeof(p->b);
d =sizeof(c);
unsigned char *e,r[8];

 
/ *unsigned char buffer[5][8];
a =sizeof(buffer[5]);* /


tSaveRecordType dd;

c =0;
c+=sizeof(tSaveRecordType);
 



int *ads;
ads +=1;

ads =0;
ads =(int *)((char *)ads +1);

printf("len is %d\n",c);
printf("len is %d\n",d);






 
/ *


 
	Week =fun();
	 
	 
 
#if 0
i=random(20);
printf("%d",i);
#endif* /

#endif


#if 1
int add;

FILE *input;
input =_tfopen("a.txt" ,"rb");

if (input==NULL)
{
	printf("error");
}
else
{
 
	printf("start\n");
 
}
#endif






	printf("df");

*/

}

#endif

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:57208次
    • 积分:794
    • 等级:
    • 排名:千里之外
    • 原创:24篇
    • 转载:0篇
    • 译文:0篇
    • 评论:7条
    最新评论