소스코드의 오류원인 부탁드립니다.

익명 사용자의 이미지

사용중인 프로세스 정렬을 출력하는 소스코드 입니다...(일종의 작업관리자인데요..)
근데 프로세스 정보를 구조체 배열에 넣는 과정에서 자꾸 메모리 침범같은데.,. 원인을 못찾고 있네요...
해결부탁드립니다.

// OpenProcess.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다.
//
 
#include "stdafx.h"
#include <Windows.h>
#include <conio.h>
#include <stdio.h>
#include <tchar.h>
#include <TlHelp32.h>
#include <string.h>
 
typedef struct USER {
	int pid;
	int ppid;
	char name[100];
}USER;
 
 
void oneProcess(USER *user);
 
int main()
{
 
	USER user[100];
 
	oneProcess(user);
 
 
 
	for (int i = 0; i<100; i++)
		printf("Parent %d Process ID %d Process Name %s \n", user[i].pid, user[i].ppid, user[i].name);
 
	_getch();
 
	return 0;
 
}
 
void oneProcess(USER *user)
{
 
	PROCESSENTRY32 pe32;
	HANDLE hProcess;
	static int count = 0;
	char str[100];
	hProcess = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
	pe32.dwSize = sizeof(PROCESSENTRY32);
 
	memset(user, 0, sizeof(USER));
 
 
 
	if (Process32First(hProcess, &pe32))
	{
		do
		{
 
			//printf("Parent %Id Process ID %Id Process Name %ls\n", pe32.th32ProcessID, pe32.th32ParentProcessID, pe32.szExeFile);
			sprintf(str, "%ls", pe32.szExeFile);
			user[count].pid = pe32.th32ProcessID;
			user[count].ppid = pe32.th32ParentProcessID;
			strcpy(user[count].name, str);
			user[count].name[strlen(str) + 1] = '\0';
			printf("Parent %d Process ID %d Process Name %s \n", user[count].pid, user[count].ppid, user[count].name);
			count++;
 
		} while (Process32Next(hProcess, &pe32));
 
 
		// 선택정렬
 
		int i, j, min;
		int tmPid, tmPPid;
		char tmpStr[100];
 
		for (i = 0; i<count - 1; i++)
		{
			min = i;
			for (j = i + 1; j<count; j++)
			{
				if (user[j].pid < user[min].pid)
					min = j;
			}
			tmPid = user[i].pid;
			tmPPid = user[i].ppid;
			strcpy(tmpStr, user[i].name);
 
			user[i].pid = user[min].pid;
			user[i].ppid = user[min].ppid;
			strcpy(user[i].name, user[min].name);
 
			user[min].pid = tmPid;
			user[min].ppid = tmPPid;
			strcpy(user[min].name, tmpStr);
		}
 
 
	}
 
	CloseHandle(hProcess);
 
}
jehnpark의 이미지

선택정렬이 select sorting을 말하는건가요?
하여간 뭔가가 잘 짤려서 뭔지는 잘 모르겠고
memcpy는 해줘야 하는데 strcpy하면 굳이 끝에 0 대입 안해줘도 돼요
아무래도 memset에서 오류난거같습니다

memset(user, 0, sizeof(USER));//에서
memset(user, 0, sizeof(USER)*100);//로

세벌의 이미지

소스코드는 <code > 와 </code > 사이에 넣어 주세요.

라스코니의 이미지

USER user[100] 로 100개 만큼 생성하고 있습니다.

do {
...
} while (Process32Next(hProcess, &pe32));

루프에서 100번 이내로 도는지 확인해 보세요. count 값을 매 루프마다 프린트해 보세요.