void PrintString(int Level , WCHAR *pszFormat , ...)

本文详细介绍了如何使用PrintString函数实现调试输出,包括函数的定义、参数使用及输出控制,适合编程初学者和经验丰富的开发者深入理解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

void PrintString(int Level , WCHAR *pszFormat , ...)
{
va_list arglist ;
WCHAR buf[1024] ;

if(Level<=g_nDebugLevel)
{
va_start(arglist , pszFormat) ;
memset(buf , 0 , sizeof(buf) ) ;
va_start(arglist, pszFormat);
wvsprintf(buf, pszFormat, arglist);
va_end(arglist);
OutputDebugString(buf) ;
}
}
#include <stdio.h> #include <stdlib.h> #include <string.h> struct String { char *data; int length; }; void initString(struct String *S) { S->data = NULL; S->length = 0; } void assignString(struct String *S, char *str) { int len = strlen(str); if (len == 0) { if (S->data != NULL) { free(S->data); S->data = NULL; S->length = 0; } } else { if (S->data != NULL) { free(S->data); } S->data = (char *)malloc(sizeof(char) * (len + 1)); strcpy(S->data, str); S->length = len; } } void printString(struct String *S) { if (S->data == NULL) { printf("Empty String\n"); } else { printf("%s\n", S->data); } } void getNext(struct String *P, int *next) { int i = 0, j = -1; next[0] = -1; while (i < P->length) { if (j == -1 || P->data[i] == P->data[j]) { i++; j++; next[i] = j; } else { j = next[j]; } } } int KMP(struct String *T, struct String *P) { int i = 0, j = 0; int *next = (int *)malloc(sizeof(int) * (P->length + 1)); getNext(P, next); while (i < T->length && j < P->length) { if (j == -1 || T->data[i] == P->data[j]) { i++; j++; } else { j = next[j]; } } free(next); if (j == P->length) { return i - j; } else { return -1; } } int main() { struct String T, P; initString(&T); initString(&P); assignString(&T,"ababcabcacbab"); assignString(&P,"abcac"); printf("T: "); printString(&T); printf("P: "); printString(&P); int pos = KMP(&T, &P); if (pos != -1) { printf("模式串在主串中的位置是:%d", pos); } else { printf("未找到模式串!\n"); } return 0; }将以上程序修改为在运行中输入T和P
05-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值