C 程序停止并停止';t执行线程为什么?

C 程序停止并停止';t执行线程为什么?,c,multithreading,winapi,C,Multithreading,Winapi,我编写了一个程序,从用户那里获取数字,然后允许输入数字,然后创建两个线程,一个用于计算总和,另一个用于计算平均值 但在给出数字后,程序停止并给出错误原因 #include<stdio.h> #include<Windows.h> #include<stdlib.h> int count ; DWORD WINAPI Sum(PVOID s) { int *sum=(int *)s; DWORD c=0; for(int i=0;i&

我编写了一个程序,从用户那里获取数字,然后允许输入数字,然后创建两个线程,一个用于计算总和,另一个用于计算平均值 但在给出数字后,程序停止并给出错误原因

#include<stdio.h>
#include<Windows.h>
#include<stdlib.h>

int count ;

DWORD WINAPI Sum(PVOID s)
{
    int *sum=(int *)s;
    DWORD c=0;
    for(int i=0;i<count;i++)
        c+=sum[i];
    return c;
}

DWORD WINAPI Avg(PVOID s)
{
    int *var=(int *)s;
    DWORD avg=0;
    avg=(*var/count);
    return avg; 
}

int main()
{
    printf("Enter the number of numbers\n");
    scanf("%d",&count);
    int *s = (int*)malloc(sizeof(int)*count);
    printf("now enter the numbers\n");
    for(int i=0;i<count;i++)
        scanf("%d",s[i]);

    HANDLE t1 , t2;
    DWORD id1 , id2 , c1 , c2;
    t1 = CreateThread(NULL , 0 , Sum , s , 0 , &id1);
    WaitForSingleObject(t1,INFINITE);
    GetExitCodeThread(t1 , &c1);
    printf("The Sum = %d", c1);
    t2 = CreateThread(NULL , 0 , Avg , (PVOID*)&c1 , 0 , &id2);
    WaitForSingleObject(t2,INFINITE);
    GetExitCodeThread(t2 , &c2);
    printf("The AVgerage = %d", c2);
    return 0;
}
#包括
#包括
#包括
整数计数;
DWORD WINAPI和(PVOID s)
{
int*sum=(int*)s;
DWORD c=0;

对于(int i=0;i
scanf
需要参考

scanf("%d",&s[i]);

请给这个问题加上一个语言标记。我假设C++。我把它放在了一起,但仍然是一样的。你有幸找到了剩下的问题:我以后会有这个荣幸的,因为我在12个小时后有一个考试,所以我需要知道。劳拉:以这种态度,你一定会自己行使这个荣誉。