Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You could do it all in just one callback function, but it might sometimes get a little messy and complicated because the function might have to decide which window it was being called for. Yes, the window handle is passed to the callback function, but that might not be enough to distinguish between dialogs or controls.

The macros CALLBACK and WINAPI should be used because (1) they are Microsoft standards and (2) if Microsoft decides to change the macros then you will be SOL if you didn't use them. The same with using int instead of HANDLE -- 64-bit programmers will find out very quickly when they begin to migrate their 32-bit windows programs to 64 bit if they did not use standard Microsoft macros because the size of the HANDLE object was changed.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

InvalidateRect() causes WM_PAINT message. CreateWindow() causes WM_CREATE message. You should not post either of those messages yourself but call the win32 api functions.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is a link I find a useful reference.

Salem commented: rep++ from Salem +2
Killer_Typo commented: great link +4
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you intend to support MS-Windows only, C# might be a better language than C++ because it is suppored to have web stuff built into the language. It is M$ answer to Java but right not I think it is only supported in MS-Windows os. I installed Fedora last weekend on my computer and saw one of the messages say something about .NET support files. So maybe linux is starting to support it too.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

sure would be nice to have a delete button so that I can delete my own post but nobody else's. I find it annoying that I cannot delete my post when I see that it duplicates someone else's or that I posted misinformation. Just simply editing the post and deleting all the text is not very pretty.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I'm indifferent to them. They are ok, but not something I find very useful.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is an example

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Its not really all that difficult -- here is an explaination of popen() and and example program. BTW you don't use system() with popen(), but call whatever program you want directly

char syscommand[BUFSIZ];
char inbuf[BUFSIZ];

             sprintf(syscommand,"des -D -k %c%c credit0_e credit0",keys[i],keys[j]);             
             if ((ptr = popen(syscommand, "r")) != NULL)
                     while (fgets(inbuf, BUFSIZ, ptr) != NULL)
                             (void) printf("%s", buf);
                     (void) pclose(ptr);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Also see this thread

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Do you mean Quantlib open source library for quantitative finance ? I don't know a thing about it, but their web site has a lot of information including documentation and links to relevant forums. The site even contains links to example programs.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Obviously, obtaining, setting up and learning how to use a graphics library to get the task done will be a bigger task than using ASCI art

And probably way too much for a first year student who doesn't even know how to draw a staight line using normal console output! OpenGL and other similar graphics programs require pretty advanced programming skills.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

hahaha funny asshole

:mrgreen: :mrgreen:

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>lol i cant drop classes
I guess you will be burning a lot of midnight oil! Better start reading, studying and practicing all those exercises at the end of the chapters. They are there for a purpose -- to help you learn.

Here is a C starter program.

#include <stdio.h>

int main()
{
   // put your code here



   return 0;
}
hygy486 commented: your an asshole +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Its unlikely you are being asked to write any of that with very advanced techniques such as using a graphics library, unless you are actually taking such a course. If this is your first year of programming then just use standard console-mode print statements to create small circles, triangles and lines. First I'd work on learning how to display a straight line. When you get that idea down, then work on learning how to draw a triangle (uses several nested loops). Once you learn that the rest of the requirements should be pretty straight forward.

>>i dont have time to look things up
Then you might consider dropping a class or two to free up some time because computer programming is very very time consuming. Also, stop going to those beer parties might help too :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

most programs that use passwords display an asterisk for each character typed. Your program probably should do that too, and it can be done within that while loop. If you look at the curses library you might find there it already a function that will do it for you. That loop also needs to check for buffer overflow, do not allow i to exceed the size of input buffer.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

And here is an example C program (freeware). I have not run this but it looks promising.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Are you allowed to use non-ansi standard functions?

You didn't answer that question. If not then you may not get any credit at all. Of course if your class is studying curses then the question is moot.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Assuming you mean MS-Windows operating system, call GlobalMemoryStatus.

Grunt commented: :) [Grunt] +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I see the program must be using curses?? Are you allowed to use non-ansi standard functions?

>>Does this look correct to you guys
How it "looks" is unimportant. Does your program compile with 0 errors and does it work ok when you run and test it?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>char *str="abcd";

There are two objects here -- the pointer itself is a variable that is on the stack. It contains the address of the string that is stored in the heap -- often in read-only memory.

[edit]Sorry Holly I didn't see your last post when I posted this. The link you posted is a much better and thorough explaination.[/edit]

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Why me?

Not just you afterall. I just saw that behavior for the first time today. I bookmaked the c/c++ forums and now when I use that bookmark the online status is greyed. Oh well, as Queen Deniweb mentioned, I'd rather see fast loading pages then have significant slowdowns just to make the online status green when it should be.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

probably because BGI requires a 32-bit compiler, which TurboC is not. Upgrade to one of the free compilers mentioned in that link.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

flame or nub. i think the latter

It wasn't a comment about linux in general, but about Ubuntu specifically. Any os that can beat world chess champion (human) is not all bad! :eek: I just don't enjoy spending hours doing something in a linux environment that takes me just minutes in MS-Windows. I have no idea about MAC, never tried one. But I hear they are great for graphics, much better than MS-Windows.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is one

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

unlike MS-Windows, not all *nix machines were created equally. A 32-bit program compiled on one *nix computer may or may not run on another 32-bit *nix computer, unless the hardware is identical. There are many different flavors of linux/unix computers and they run many different chip sets (or whatever they are called) (80x88, risk, etc). Programs have to be recompiled for each of these different machine types.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Well, I finally decided that os is not for me afterall. Its fine for someone who just likes to play games, surf the web, but leaves a lot to be desired for programmers. It didn't have any of the X11 header files, so after downloading them, the build failed with several errors in *.c files. So I finally gave up, went back into XP, deleted the partitions that Ubuntu had created and reformatted as NTFS file system for XP use.

Oh humm.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you probably need to compile your program to support UNICODE. You can't treat a unicode-written file as if it were an ascii file becuase it is not the same file format. UNICODE characters are two or more bytes per character.so you need to use char data type with wchar_t and use unicode replacements for string handling functions. c++ std::wstring instead of std::string.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The problem you see is due the the font the editor uses. Look around the editor's menu and see if it allows you to change the font, then find a font that supports the characters you want to use.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

He means FreeBSD :P I didn't find it very easy to install...but I was using a 98, 8 year old computer!

You're right -- sometimes I'm a little dyslexic. And it doesn't matter how old the computer is, FreeBSD is still terrible to install.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Just finished installing this linux-like os and had to post a message. Its kind of nice os, open source and free of course. It all fits on one CD and has several packages that can be added after installation. Its truly an os-for-dummies, It was even easier to install then Red-Hat. I have also tried FreeBDS and now use the book (not free) as a door stop. Horrible. Never did get it installed correctly even after several weeks trying. But this Ubuntu os is the easiest to install that I have tried yet.

Now all I have to do is figure out how to use that gnu compilers. I love Microsoft compilers, and will surly regret having to put up with ancient vi.exe and awkward command-line compiles. Ubuntu does have a couple graphical text editors. And something called Kommander widget editor.


If you don't know what Ubuntu is, (this is all I know about it too so don't ask me any questions :) )

Ubuntu is a South African ethical ideology focusing on people's
allegiances and relations with each other. The
word comes from the Zulu and Xhosa languages. Ubuntu
(pronounced "oo-BOON-too") is seen as a
traditional African concept, is regarded as one of the
founding principles of the new republic of South Africa
and is connected to the idea of an African Renaissance.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is one way to do it. If you google for "play sound" you will find other ways.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

look at the structure -- credit is an array of floats and you are attempting to use it as if it were a single float object. Change the structure to remove the arrays

struct cgrade
 {
    char course[50]; // room for 50 character course name
    float credit;
    float grade;
 };

>>gets(GPA.course);
never, ever use gets() function because it can cause your program to crash if you enter more characters than the input buffer can hold. Use fgets() instead

fgets(GPA[i].course, sizeof(GPA[i].course), stdin);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> Is there some sort of wildcard search function in C?

No

>>Detailed explanation.

write your own. c++ boost libraries have regexp libraries, but of course that isn't C.

Here is something in C from GNU that might interest you.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> Is there some sort of wildcard search function in C?

No

>>Detailed explanation.

write your own. c++ boost libraries have regexp libraries, but of course that isn't C.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I think you are encountering what is commonly called "undefined behavior" or "implemention specific". In C, const int a points to a memory location that can be modified, but in c++ variable a is not located at any memory variable but just used as an immediate value, which is similar to just hard-coding a literal value in the program. You could have rewritten the lines like this:

c++
 printf("address of a=%u\t%d\n", &a,10);

c
 printf("address of a=%u\t%d\n", &a,a);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

that one of the benefits of posting code on these boards -- often other eyes can catch errors that you can't.

aeinstein commented: Nicely done. +10
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

making that change and the program runs without a problem. Don't know if the output is what you want or not though.

My compiler is not c99 compilant, so I use new to allocate the arrays, but the output should be the same.

sb
(?:(?:[a-z90](?:-?[a-z90]+)+)(?:\.(?:[a-z90](?:-?[a-z90]+)+)){0,4})

i
((15[1-4]|1[1-4][1-9]|[0-1]?[0-9]?[0-9])(?:\\.(15[1-4]|1[1-4][1-9]|[0-1]?[0-9]?[
0-9])){3})

dm
(?:(?:[a-z90](?:-?[a-z90]+)+))

h
((??:(?:(?:[a-z90](?:-?[a-z90]+)+)(?:\.(?:[a-z90](?:-?[a-z90]+)+)){0,4})\.)?(?:(
?:[a-z90](?:-?[a-z90]+)+))\.([abcd]{2,4})|((15[1-4]|1[1-4][1-9]|[0-1]?[0-9]?[0-9
])(?:\\.(15[1-4]|1[1-4][1-9]|[0-1]?[0-9]?[0-9])){3}))(?:\:(0-9]+))?)
Press any key to continue . . .
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The problem is classic case of buffer overrun.
char i[iNumLen + 1];
The above does not allocate enough space for the result string.

Boost libraries contain a regular expression c++ class. It might be worth tossing out this poort c implementation and using boost.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It used to happen to me lot of times,
The problem is that you have included the header file that contains this function , but forgot to include the .lib or .a files with your files.

I guess you didn't bother to read any of the other posts. If you had, you would have found out that there is no library for the functions he is calling.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Unlike most win32 api functions mapi does not have a library. Instead, you will have to learn how to use LoadLibrary() and GetProcAddress(), as explained in MSDN

To use the Simple MAPI functions, compile your source code with MAPI.H.
MAPI.H contains definitions for all of the functions, return value constants,
and data types. To call a Simple MAPI function, load MAPI.DLL and use the
Win32 GetProcAddress function to acquire an entry point. The function
calling conventions should be FAR PASCAL.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

MS-Windows specific -- calls them file handles, otherwise the concept is the same as stated previously by Rashakil.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

csv format uses commas between fields, and I believe that text fields which contain commas should be enclosed in quotes.

FILE *fp = fopen( "file.csv", "w" );
fprintf( fp, "%d,\"%s\",\"%s\",\"%s\",%d,\"%s\",\"%s\",\"%s\",%d\n", index, delim, deltime, delim, 
         type, delim, filename, delim, filesize );
fclose( fp );
Grunt commented: Good - [Grunt] +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

from the command prompt just redirect the output to a file

c:> myprog.exe >file.csv <Enter>
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you mean nothing enforces it on YOUR operating system. Run that program on *nix or MS-Windows and it will be different.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

No it works, i tried it.


Why i need to use

char*

is because windows functions only accept char*

yes they do, and std::string's c_str() returns a const char*. You need to tell us the win32 api function you are attempting to call. But general rule of thumb is that when the parameter is const char* then you can pass std::string's c_str() method. If it is char*, that normally means the function might attempt to change the string, so you have to pass it a char buffer that is modifyable, and not just some character pointer.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Actually, all memory is marked writable, mainly because I was too lazy to look up the bits to set for read-only memory :-) Keep in mind:

No, because I never wrote a strtok after reading about it and how it sucked...

I didn't realize you are writing your own os, your own compiler and all the functions that are normally in the standard C libraries. So your ocmpiler does not meet ansii standard c. Since you are the only one using it I suppose you can do whatever you like.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
// BTW, this will eventually return a string containing the token_numth token. But I'm just trying to get it to work for now.
void strsplit(const char *str, char splitchar, int token_num)
{
	char *delimeter = "\0";
	delimeter[0] = splitchar;
^^^ delimiter is a ponter that oritinally points to someplace
in read-only memory.  You can't, in most cases, write to read-only memory like that.  
When you do, either you will get runtime errors or undefined behavior
	int i;
	strcpy(str, line);
^^^ 	attempt to copy something to read-only memory.  Note that your program passed a
 string literal to this function, and all (or most) string literals reside in read-only memory

        char *token = line; /* point to the beginning of the line */
^^^ where is variable line defined?  I don't see it anywhere

	for (i = 0; *token; i++) /* loop through each character on the line */
	{
		/* search for delimiters */
		size_t len = strcspn(token, delimeter);
		token[len] = '\0';
^^^ this is identical to strtok().  You may as well have used it.

		/* print the found text: use *.* in format to specify a maximum print size */
		printf("token[%2d] = \"%s\"\n", i, token);
		 /* advance pointer by one more than the length of the found text */
		token += len + 1;
	}
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I already posted it three or four times. Read my last post. Besides, there is only one Windows Platform SDK. It says "Windows® Server 2003 SP1 Platform SDK" but its for XP too and is the correct version that you need.

I don't recall what version of Windows you are using, but you should read the systems requirements before installing that SDK.

System Requirements

* Supported Operating Systems: Windows 2000; Windows Server 2003; Windows XP 64-bit; Windows XP Professional Edition ; Windows XP Service Pack 1

* Hard Disk Space. Choose a disk drive with a minimum of 1 GB of free space.


* High-Speed Internet Connection. If your connection speed is 56 Kbps or less, it is best to purchase the low-cost SDK CD (US/Canada or International) or install the Web Download.


* Development Tools. To build the C/C++ samples, you must have a C/C++ compiler. If you are using Microsoft Visual C/C++®, run it at least once before installing the SDK. This will ensure that the environment variables are correctly configured. To build the Visual Basic samples, you must have Microsoft Visual Basic®. This SDK does not support working with Microsoft Visual C/C++®, 6.0 as support for VC 6.0 has ended. The last SDK that will work with VC 6.0 is the February 2003 Edition, you can order a CD on the fulfillment site. Side by side installations are not supported.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Congratulations on finding a Quine.

Just substiute for readability

printf( "char*str=%c%c%c;main(){printf(str,34,str,34);}", // str,  
        34,
        "char*str=%c%c%c;main(){printf(str,34,str,34);}", // str,
        34 );

The first one contains 3 % conversions for the 3 params which follow
The second one is just a string which happens to contain % characters
The 'magic' is that it's the same string.

Sorry, but I don't see any magic in it at all. The 3d argument is just used by printf() as an address of a string displayed as a character not as a string. He could have substituted "Hello World" there and the o/p would have been similar.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The O/P you posted is wrong (the actual o/p may be slightly different from one computer to another because the second %c in the format string.)

char*str="∟";main(){printf(str,34,str,34);}

The formatting string is the first argument to printf() -- it does not have to be a string literal and can contain other characters besides %s, %c %f etc. printf() just displays the characters that are not followed immediately by '%' character.