There is no standard way of replicating kbhit, getch, etc as the standard input functions are buffered and block while waiting on user input.
I remember reading an article somewhere where buffering could be turned off, but it's not portable. Try milling over the results from google and see if any will work for your situation.
Good luck
User Profile
Collapse
-
I don't know to be honest; looping and generating a returnable value has me stumped. I can only think of something like
SUM would still be treated as a non-constant, I believe, so int Newbuffer[SUM] probably wouldn't compile. Hopefully, donbock,...Code:#define SUM_X(struct_var)\ (\ (struct_var[0].x) + \ ...\ (struct_var[5].x)\ ) #define SUM SUM_X(my)Leave a comment:
-
I'm not sure that a macro works well for summing and returning a value. You might try a function instead.
However you get the sum of ".x", you cannot size an array like you're wanting to do. Use dynamic allocation instead.
...Code:// declare struct ... int sumX(TYPE_TEST *arr, int arr_size) { // code to sum "x" and return its value } ...Leave a comment:
-
srand doesn't return a value, but you're trying to assign it as though it did to nInRa. srand is your seed, which generally takes time(NULL) as its argument... include time.h or ctime
you'd want rand to generate the "random" sequence.
Code:srand((unsigned)time(NULL)); nInRa = rand() % 3 + 1;
Leave a comment:
-
If you're wanting to allow alpha-numeric input, then you might try using a std::string or char array for order instead. Your sentinel would need modification though.
A char type would work too, but leaves the little newline gremlin to deal with.Leave a comment:
-
C and WinAPI: hwnd question
I've started working on win32 programming, and have a question regarding hwnds. I've milled over tutorials and they seem to vary - I've tried using the following 3 methods, but was wondering which, if any, is preferred?
Code:... static HWND hwnd1 = 0; ... WM_CREATE : hwnd1 = CreateWindow(...); ......Code:HWND function(...) { return CreateWindow(...); -
I think the op is wanting to parse the string to extract the integer values. if so, sscanf should work.Leave a comment:
-
you could probably get away with using two time_t objects to make a crude timer. it would be portable.
#include <time.h>Leave a comment:
-
getScore() needs access to your input file. since you've created the fstream object in main, you could modify getScore's parameter list to take "grades" as a second argument.Leave a comment:
-
check "b" to see if it's picking up the new line char instead of your expected input; mixing data types with scanf can be a nuisance.Leave a comment:
-
You can use a variable to count the lines as you read the contents of the file. It sounds like it should be the index position for the array as you read the file.
the read_data function looks incomplete; what value does the return represent? the status of the file? the number of elements to read? some other value?
as a side note, like sscanf and scanf, fscanf returns the number of successfully converted and stored...Leave a comment:
-
The errors occur because your prototype doesn't match your call. The prototype takes two floats as arguments and returns a float; neither the return value nor the argument list should be float arrays.
you're trying to do below, but it is incorrect for the function prototype and its definition.Code:float compute_bmi(float, float);
height, weight, and bmi have all...Code:array = compute_bmi(array, array);
Leave a comment:
-
Your best bet would be to copy / paste any compiler errors in your topic. If the code you posted is the same as the compiler errors, then line 10 *looks* okay.
line 28 has an issue. The prototype returns a float and not an array; however, I don't believe C allows aggregate assignment of arrays. wfc??Leave a comment:
-
the call here isn't right. you haven't declared any variables named input or key. declare a char array and an integer variable, and pass them as parameters to input.Code:input(message[100], key);
Code:char array[100] = { 0 }; int key; input(array, key);...Code:void input(char message[100], int& key) { cout << "Please enter an encrypted message:Leave a comment:
-
With VS, you should be able to include windows.h and link kernel32.lib to your application for FindFirstFile, FindNextFile, etc.
For the other, I cannot recall if you mentioned whether or not you were using c or c++, but you can build the dir command using sprintf or sprintf_sCode:#include <windows.h> #pragma comment(lib, "kernel32") // program code
...Leave a comment:
-
If you're using VS, then you should be able to make use of CreateFile, FindFirstFile and FindNextFile for processing directories and files. The links have examples for doing what you're trying to do.
The only other thing I can think of is to build a command string for DIR, and pass the arugments using system. You can dump the result to a file instead of the console window, which you could then open, read, and process as needed....Leave a comment:
-
I wish that I could learn to think like a programmer; thank you for that! Just what it needed. :)
CheersLeave a comment:
-
Thank you for the reply... as always, I appreciate your time and feedback.
The problem went away after moving the (tmp->canceled == TRUE) test to the bottom of the do-while. I still have no clue as to way the program bogged down if that test was at the top of the loop.
SetEvent was called within one of the WM_USER messages. The thread ended, but had a sort of delayed effect before. Moving the canceled test "fixed...Leave a comment:
-
thread appears to run after SetEvent
I don't know if I've setup the thread correctly or not, but its behavoir isn't what I'd expect. I'm creating the thread within a BN_CLICKED message
Code:typedef struct my_TNFO { HANDLE h_event; HANDLE h_thread; DWORD thread_id; BOOL running; BOOL init; BOOL canceled; } TNFO;
...Code:... if(HIWORD(wParam)
No activity results to display
Show More
Leave a comment: