gpt4 book ai didi

c - 随机数生成-未声明的标识符

转载 作者:行者123 更新时间:2023-11-30 17:58:52 25 4
gpt4 key购买 nike

到目前为止,我还没有很好地将部分程序代码组合在一起

#include <windows.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>

#define MAX_BUFF_SIZE 1024
#define IDM_FILE_RUN 40001
#define IDM_APP_EXIT 40002

//Window Function
LRESULT CALLBACK WindowFunc(HWND, UINT, WPARAM, LPARAM);


int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst,
LPSTR lpszArgs, int nWinMode)
{

WNDCLASS wcls;
HWND hwnd;
MSG msg;

// Name of window and window class
LPCWSTR szWinName = L"Threads Program";
LPCWSTR szClassName = L"ThreadsProgram";


wcls.hInstance = hThisInst;
wcls.lpszClassName = szClassName;
wcls.lpfnWndProc = WindowFunc;
wcls.style = 0;
wcls.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcls.hCursor = LoadCursor(NULL, IDC_ARROW);
wcls.lpszMenuName = NULL;
wcls.cbClsExtra = 0;
wcls.cbWndExtra = 0;
wcls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);

// Register windows class
if(!RegisterClass(&wcls))
{
return 0;
}

// Create main window
hwnd = CreateWindow(szClassName,
szWinName,
WS_OVERLAPPEDWINDOW,
100,
100,
400,
400,
HWND_DESKTOP,
NULL,
hThisInst,
NULL );

// Show main window
ShowWindow(hwnd, nWinMode);
UpdateWindow(hwnd);

// Message loop
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}



LRESULT CALLBACK WindowFunc(HWND hMainWindow, UINT message,
WPARAM wParam, LPARAM lParam)
{
static char textBuffer[MAX_BUFF_SIZE];
static int nRead;


switch(message)
{
case WM_CREATE:
{
HMENU hMenu;
HMENU hMenuPopup;

// create menus
hMenu = CreateMenu();
hMenuPopup = CreateMenu();

// populate menus
AppendMenu(hMenuPopup, MF_STRING, IDM_FILE_RUN, L"&Choose Balls");
AppendMenu(hMenuPopup, MF_STRING, IDM_APP_EXIT, L"&Exit");
AppendMenu(hMenu, MF_POPUP, (UINT_PTR)hMenuPopup, L"&File");

// attach menus to main window
SetMenu(hMainWindow, hMenu);
}
break;
case WM_COMMAND:
{
// Obey command
switch(LOWORD(wParam))
{
case IDM_FILE_RUN:

{
srand (time(NULL));
for (int i = 0; i < 6; i++)
printf ("%i\n", (rand ()% 49) + 1);




return 0;

}
break;
case IDM_APP_EXIT:
SendMessage(hMainWindow, WM_CLOSE, 0, 0);
break;
}
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hMainWindow, message, wParam, lParam);
}
return 0;
}// Window function

错误消息说我有一个未声明的标识符及其与我的随机数部分相关,

case IDM_FILE_RUN:              
{
srand (time(NULL));
for (int i = 0; i < 6; i++)
printf ("%i\n", (rand ()% 49) + 1);

return 0;
}

我不确定我需要写什么以及我需要在哪里写它来修复它。

谢谢

Error   9   error C2059: syntax error : ')' 108 1
Error 6 error C2065: 'i' : undeclared identifier 108 1
Error 8 error C2065: 'i' : undeclared identifier 108 1
Error 4 error C2143: syntax error : missing ')' before 'type' 108 1
Error 2 error C2143: syntax error : missing ';' before 'type' 108 1
Error 3 error C2143: syntax error : missing ';' before 'type' 108 1
Error 5 error C2143: syntax error : missing ';' before 'type' 108 1

最佳答案

这可能不太可能,但是将当前的 for 循环更改为如下所示:

  int i;
for (i = 0; i < 6; i++)
...

可能你的编译器不喜欢在 for 中声明变量(我的编译器不喜欢,除非我给它一个特殊的命令行选项)

关于c - 随机数生成-未声明的标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11910690/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com