如果我有这个功能:
printAll(const char *message, ...)
{
va_list argptr = NULL;
va_start(argptr, message);
// todo: how to printf all the arguments in the message?
va_end(argptr);
}
Run Code Online (Sandbox Code Playgroud)
假设我像这样调用函数:
printAll("My info: Value1 = %d, Value 2=%d", 1, 2);
Run Code Online (Sandbox Code Playgroud)
在这一行:// todo:如何printf消息中的所有参数?
我怎样才能打印出来以便:
My info: Value1 = 1, Value 2=2
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我编写了以下代码来演示同一进程的2个线程之间的竞争条件.
`
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
int c = 0;
void *fnC()
{
int i;
for(i=0;i<10;i++)
{
c++;
printf(" %d", c);
}
}
int main()
{
int rt1, rt2;
pthread_t t1, t2;
/* Create two threads */
if( (rt1=pthread_create( &t1, NULL, &fnC, NULL)) )
printf("Thread creation failed: %d\n", rt1);
if( (rt2=pthread_create( &t2, NULL, &fnC, NULL)) )
printf("Thread creation failed: %d\n", rt2);
/* Wait for both threads to finish */
pthread_join( t1, NULL);
pthread_join( t2, NULL);
printf ("\n");
return …Run Code Online (Sandbox Code Playgroud) 我试图在c#中编写一个正则表达式来检查日期(DD/MM/YYYY).
任何日期(01/01/0000)或(12/12/9999)也可以.日期时间必须是01-12,月份时间必须是01-12,年份时间必须是0000-9999,它们之间必须是"/".
下面是我的SQL语句
DECLARE @dStart datetime ,
@dEnd datetime
SET @dEnd = GETDATE()
SET @dStart = DATEADD(mm, -6, @dEnd)
Select * from MyTable
Where TheDate Between @dStart AND @dEnd
Run Code Online (Sandbox Code Playgroud)
这将返回今天的所有记录减去6个月的数据.
但我希望这个月数据加上前5个月的数据.
目前它也将从3月返回记录.
我正在使用masm汇编程序,我正在使用kernel32.lib来创建堆内存,但是在HeapCreate过程的Windows API页面上,它并没有告诉我它的返回值存储在何处.(即堆的句柄)我会假设它存储在EAX?因为大多数程序都将其返回值放入EAX.在我调用HeapCreate之后,我调用HealAlloc在我的堆中分配一些内存:
INCLUDE \masm32\include\kernel32.inc
INCLUDELIB \masm32\lib\kernel32.lib
.CODE
PUSH DWORD PTR 00h ;max size
PUSH DWORD PTR 00h ;initial size
PUSH DWORD PTR 04h ;flOption
CALL HeapCreate
PUSH DWORD PTR 04h ;dwBytes (the size in bytes)
PUSH DWORD PTR 04h ;dwFlag
PUSH EAX ;I am not sure if the heap handle is stored in EAX or not?
CALL HeapAlloc
END
Run Code Online (Sandbox Code Playgroud)
基本上,我不知道HeapCreate存储返回值的位置.如果有人能澄清在哪里,我会很感激.
谢谢
void* heap = malloc(100);
char *c = heap;
strcpy(c, "Terence");
printf("heap = %s\n", heap);
free(heap);
heap = malloc(100);
printf("heap = %s\n", heap);
Run Code Online (Sandbox Code Playgroud)
输出是:
heap = Terence
heap =
Run Code Online (Sandbox Code Playgroud)
这就是我的期望,但现在我有一个更复杂的代码,结构与上面类似,但输出如下:
heap = "Terence"
heap = " ren "
Run Code Online (Sandbox Code Playgroud)
类似的东西.
堆似乎还没有被清理干净?
有办法解决吗?