TkTkorrovi 69 Junior Poster

Disgusting, i'm for all programmers to get paid for what their work is worth, not playing with them by taking job from programmers somewhere and giving it to programmers somewhere else. And concerning your government supported IT companies led by communists, i would advise not to have any deal with them, i would never work for such companies and i'm by far not the only one. Look, finally, even the programmers who develop the open source software, must get payment for the work, there is no other field in the world where so much work is done for free.

TkTkorrovi 69 Junior Poster

Well then you only believe the authorities -- if you think that the authorities are always right and authority is the only way to establish credibility, then the burden of proof lies on you.

TkTkorrovi 69 Junior Poster

You can also compile gtk programs both in linux and in windows cmd console, like this:

pkg-config gtk+-2.0 --cflags --libs | xargs gcc something.c -o something.exe

if you have xargs, which is in the findutils package of gnuwin32. This though likely doesn't work in any IDE. One good thing to remember about windows console is that clicking the mouse right button adds the content of the clipboard to the command line, and selecting text and pressing enter, copies the selected text into the clipboard.

TkTkorrovi 69 Junior Poster

One way how you certainly can use gtk in cygwin with win32 gdk backend, is to install gtk source, and compile it with the appropriate options. This is not likely a very convenient option for many though. You can also use mingw gtk with cygwin gcc, when you use the -mno-cygwin flag, as it is said in the Tor Lillqwist site http://www.gimp.org/~tml/gimp/win32 This flag may though cause some problems in cygwin, but it's still likely somewhat better than using mingw, when you have cygwin.

TkTkorrovi 69 Junior Poster

There are no square or cube functions or operators in standard c. There are though functions for logarithms and such. It also depends what precision the result should be, if it has to be a very high precision, you should use some special math library. Please, also, write a bit more exact title to your threads, so that others would also see what the thread is about -- c means nothing because all this forum is about c.

TkTkorrovi 69 Junior Poster

There are function pointers in c, using which you can create structures which a similar to objects in c++, but not all concepts of c++ apply to c.

TkTkorrovi 69 Junior Poster

Please see this thread http://www.daniweb.com/forums/thread86245.html I have used gtk with mingw quite a lot, but unfortunately not with cygwin. I know though, that there is a cygwin gtk port for windows gui as well, but unfortunately i have not much idea how to find it. The gtk package which you mentioned is likely gtk2-x11, i know there is also gtk+ package for cygwin, but this might be for gtk 1.2, not gtk 2... But what concerns mingw port, please ask if you have any problems installing it, likely better in the original thread. There used to be some packages for installing all gtk development files at once, but all which i ever knew, are unmaintained and broken by now. Many things necessary for gtk are really part of gnuwin32, which can be installed completely, but there would be a lot of things unnecessary then.

TkTkorrovi 69 Junior Poster

The biggest problem is graphics interface. There are no standards, only opengl is really standard, but it doesn't make no sense to learn it for anyone who is not going to write only 3d games... Graphics interface is something which has not developed yet to the stage where creating standards would be possible.

TkTkorrovi 69 Junior Poster

Well it's only my opinion, or something which i truly think is a good advice, but of course you are free to use whatever you like or have other opinion.

Do they claim that their bgi interface is also a standard? No 2d graphics interfaces are standard, except xlib which is a standard of x consortium, and gtk which is a part of the gnu, if one considers gnu a standard. So the only thing what makes difference, is how free and open they are. IDE-s are not standard either.

TkTkorrovi 69 Junior Poster

In fact, i only wanted to joke, i really didn't expect that the reaction to that is the accusation in "hijacking". I thought i was among friends, but found that i'm among enemies. I'm very disappointed in you indeed, and i think that you well understand that i have a serious reason for that.

TkTkorrovi 69 Junior Poster

Well i'm not completely sure what you exactly want to do, the biggest problem with your code is that there's so much vertical space everywhere, it's right that it's good to distinguish parts of the code, but it's not good to do it too much. It's equally important in making the code readable, that it was easier to view the code, so that a function, or at least every distinct part of it, would have a length not more than a single screenful. There were also several other things not so right in your code, but it would be too long to write all that here... Nevertheless i guess something like this:

static int previousgrade;
if (studentgrade > previousgrade)
	strcpy (HighestAverage,
		StudentName);
previousgrade = studentgrade;

At that, HighestAverage should also be a char array of appropriate size, it was just char in your code. Also notice what static int previousgrade means. When we declare a variable static, then it means that this variable exists during all program execution. In spite that we do that inside a function, it is not the same as variables without any specifier declared inside a function, these variables exist only from calling the function until returning from it. But in spite of that, previousgrade has a block scope, because it is declared only inside the function, which means that we can have a global variable or variable inside another function, with the same name. It is good to have as few global variables as …

TkTkorrovi 69 Junior Poster

If one can do things shortly, then the code often does much more things than it was intended to.

Iamthwee, i don't quite understand, who owns the threads here, when they are "other people's threads" and when one can hijack them. I don't know, maybe here is some secret club who owns the threads, which i was not aware of, so far i thought that anyone can write here... Please at least avoid writing nonsense, and using offensive and inappropriate words like "hijacking". Not that i so much care, but i think it would be more pleasant for other people not to see such offensive language here, thank you.

TkTkorrovi 69 Junior Poster

Concerning the code, it often does...

TkTkorrovi 69 Junior Poster

Hehe, the size of this code is already most of my gtk asteroids, this shows how inefficient the code may be...

TkTkorrovi 69 Junior Poster

Good, then the notepad has been improved since i last used it, it is that i never use it anyway...

TkTkorrovi 69 Junior Poster

Would be much more time effective if you would abandon this IDE.

TkTkorrovi 69 Junior Poster

It is the nature of programming, that there always appear some floating pumpkins everywhere... Therefore it's good to go with some serious development, this as a rule always ends with the right solutions. And GTK is one such thing, whatever it would be some years from now, it would be the right thing, and if anything there is not good yet, this will certainly be improved. I'm also the most sure, that one day there would be a simpler version of GTK, where the unnecessary things are eliminated, this is the way how the things develop. In fact, there even was a thing called easygtk, but this is not maintained any more, likely the time for such didn't come yet.

TkTkorrovi 69 Junior Poster

I would not recommend any IDE, because finally the only thing the IDE does, is that it only makes things more complicated. Who needs these unnecessary rubbish files which IDE always creates, the additional necessity to add all your files in the project, and in addition to all that, making it impossible to use many compiling methods, by writing different makefiles in different places of the source tree etc. IDE is also almost never a standard, different IDE-s have different files and options, the only thing which is really standard is compiling command-line or using makefiles, with a standard cross-platform compiler like gcc. When we write our code, we kind of also have to make it sure that others can compile our code the same way we do, achieving the same results, and it's not good to add to the code a project files of an IDE which the user even may not use. This is finally, the very meaning of the code, this is why it is code, that others can use it the way it is, to achieve the same results. But when one considers an IDE inevitably necessary, then the best choice is likely anjuta, of which there is now a windows version. This is the most widespread IDE in linux, and so kind of most developed, cross-platform, and therefore the best open source one in windows also.

TkTkorrovi 69 Junior Poster

Download mingw at http://downloads.sourceforge.net/mingw/MinGW-5.1.3.exe?modtime=1168811236&big_mirror=1
Install it in the directory \mingw. Add \mingw\bin directory to the path, changing start > settings > control panel > system > advanced > environment variables > local variables > PATH. The paths there are separated by semicolon. start > run > cmd, go to your directory where your file is, and run

gcc yourfile.c -o something.exe

When there are errors, you have to fix them. Finally, when it compiles, run something.exe, that's all :)

But notepad is not good for writing code, the worst is that it doesn't show the line number, and doesn't enable you to go to a certain line number, either. But compiler says the line numbers where the errors are, and this is often the only way how you can find these lines. I think the best advice is, download and install gvim http://www.vim.org, and use it instead of notepad. For simple editing, it's not anyhow different than notepad, only if you remember to press i before you start editing. But later, you would find many things which it can do for you, to make both editing and even compiling your code easier. gvim is a programmers editor and so something the programmers use to edit, programmers don't use notepad ;) One thing which you should remember, is that windows explorer doesn't change the directory in the shell. So that when you are in some directory with windows explorer, and then run the cmd …

TkTkorrovi 69 Junior Poster

Dunno, try to replace a node with a link to another node... Anything such is difficult though, as when the module loads, it used to create its nodes, so you have to do that always after the modules load, unless you can uninstall some module or somehow configure it... Hope that you at least want to do that in linux...

TkTkorrovi 69 Junior Poster

I see now that this code doesn't generate random numbers, but some kind of distribution, still the same applies.

TkTkorrovi 69 Junior Poster

At least one sleep function is cross-platform -- g_usleep in glib.

TkTkorrovi 69 Junior Poster

BTW, what concerns SDL, it's also not so modern low level graphics library any more. Cairo http://cairographics.org is much newer, and enables to draw antialiased text and graphics, also transparent, it's also not very complicated at all. Cairo is a part of GTK, and is its low-level engine through which the graphics in GTK is done. After GTK started to use cairo, the quality of all GTK applications improved tremendously, which i have seen myself in linux. The gnome desktop, web browser, all the graphics in linux became, how my impression was, better than that of windows xp. But unfortunately, there is likely yet no way to use cairo separately, or even to use it directly from gtk. Or, when there is a way, then it likely doesn't work very well yet, at least not so well that they would consider cairo functions as a part of the api, and also did include them into official api reference.

TkTkorrovi 69 Junior Poster

Maybe binary search, it's the most simple, when the time is not so much important, and when the arrays are static... Just keep things in order...

TkTkorrovi 69 Junior Poster

I would say you either use static arrays, which you of course also can allocate and free in the end, as you have plenty of memory, 1000 bytes and even 10 000 bytes is just nothing, or you use a linked list. But something in between, like reallocating the array, is not a good and clear solution, and may cause additional problems. But concerning speed, linked list is not even so much better than using the forward and reverse array, as i said, because you must still go through the linked list for finding an element. To make it faster, you can of course use a binary tree, but you should decide whether you need so much speed that it's worth to make things that complicated. Both singly linked and doubly linked lists and also hash tables are btw also implemented in glib, which is a part of GTK. It may be worth to use them if there is a need, because they eliminate the risk of any mistake in implementing such things just in c.

TkTkorrovi 69 Junior Poster

>> This may be a solution only for a very short delay, less than 5 milliseconds.

TkTkorrovi 69 Junior Poster

Yes but none of these is used very widely, and is not near as complete as GTK... It is one general knowledge about using software, that it's not worth to use any minimal solutions, but to use a more complicated one instead, and use only simple things from it. Because when the need may be, you would have all the facilities you need, not that your simple thing just cannot do something. And as i said, these are not very widely used, which also means that the library you use may go out of use, which happens when no one maintains it any more, making it to work together with all the possible newer things. Then you just jump from one library to another, this is not simple any more, and may still end up by using something decent... I know it's a hard decision to start to use GTK, because as a whole it is terribly complex, but you don't have to use everything, for simple things it's not so terribly difficult at all. But it's a good and decent thing, which works on every platform, mostly without *any* changes, and enables to do all the things you may ever need for graphics and graphical user interface, whenever the need may be. And also, GTK has a lot of users, so much easier to find people who may help, SDL has also a lot of users, most writing only games though, but its many GUI-s have not so many …

TkTkorrovi 69 Junior Poster

Yes. As i understand it's something about card game, these calculations are likely used for generating some random numbers. The % operator gives the remainder, so i % 13 always gives a number from 0 to 12, if i is positive, no matter what value i has. The << operator increases the number by shifting it left by one binary place, which means that << 1 is the same as multiplying by 2, << 2 the same as multiplying by 4, but a left shift is much faster than multiplying. What this gives is a random number which changes by a certain bigger unit, say by 4, which is sometimes necessary for a certain random behaviour. And then, i += i / 13 is just the same as i = i + i / 13...

TkTkorrovi 69 Junior Poster

So you want a somewhat dynamic array. For really dynamic array you should implement a linked list, which is not very difficult either, but you must be careful because mistakes in implementing it can easily cause a memory leak. But it depends, how are you going to use your array. If you want to use it for example for fifo buffer, it's much easier to implement it with a normal static array, but of course don't forget to always check the array boundary. If you only need to delete elements from the beginning, you may consider writing array in reverse, which is not difficult, but is somewhat easier and more logical to handle. But if you may need to delete anywhere in the array, then again it's important how are you going to use it. Is the order of the elements important or not, how much your array is expected to grow, how much it would be changed. Based on that, in some cases, especially when the order of the elements is not important, you may just leave some empty places where you delete, and add new values there when necessary, this is also not difficult to implement, and has been used for example even in the indexes of certain databases. But of course when everything is expected to change too much, and has to be fast at that, you may consider using a linked list, though there would rarely be a need for that, especially considering that a lot …

TkTkorrovi 69 Junior Poster

Yes OS supposed to free all the memory allocated by the program when the program exits. But nevertheless, it's a good habbit to free all allocated space when no longer needed, because the program may later be changed in a way that memory would be repeatedly allocated, and the amount of unused allocated memory would constantly increase when we forgot to free it. The failure to free the allocated space when no longer needed, is called memory leak. This may happen when we forget to free the memory, or when we are not able to do it, because we for some reason lost the pointer pointing to the allocated memory, as was the case above. Memory leak is harmful because it may cause the amount of memory allocated by the program to increase without control while the program runs. This may easily become serious when we allocate large amounts of memory or allocate frequently (in fact, some systems never allocate less than some 4 kb page at a time), everything may happen fast, and sometimes may well be possible that our program allocates all the available memory in the system, even if we have a gigabyte of memory.

TkTkorrovi 69 Junior Poster

Hey, if you so much want something to do... In my GTK Asteroids http://www.daniweb.com/code/snippet744.html i notice that the enemy bullet sometimeas goes through the ship (i didn't notice any other object to anyhow cross without collision). It's very rare, and harldy ever a big problem in the game, but it sometimes happens... I don't know whether there was a bug in the collision detection in the original version, or i spoiled something with my clumsy hand, but the bugs and fixing them is inevitably a reality in the programming. This is a quite simple game, and doing it wouldn't likely be very difficult. But if you would be able to fix it, then you know already something about programming :)

TkTkorrovi 69 Junior Poster

I don't know how to explain it the best... Look, there are variables, which in c terms are really called objects. We can consider these objects as folders, which contain something. Folder has two different properties, it usually has a name, and it has its physical location, somewhere on the shelf. Now we can give someone a copy of the folder, in which case he doesn't see the folder itself and may not know anything about the physical location of the folder. Or we can give him access to the folder, in which case he knows its physical location, can change its content, and can also rearrange the folders on the shelf. The folder name is the name of the object (variable), and the physical location of the folder is its reference, which is the value of the pointer (we may consider that the physical location of some folder may be written in another folder, which is pointer). By knowing the physical location of the objects, we can do many things. We may refer to these objects anywhere, giving access to them (enabling others to change them), and we can arrange the objects, physically or logically, any way, the simplest is the array, which in c can always be accessed by pointer (when array is a pointer, then array [n] is always the same as *(array + n)). More complex are the linked lists, binary trees etc, which enable some dynamic arrangement, ie we don't have to change the physical …

Salem commented: Good link to the Jensen tutorial, which is one of the best +9
TkTkorrovi 69 Junior Poster

select... pauses any way you want

TkTkorrovi 69 Junior Poster

I want to say only that, use some more modern compiler than turbo c, like gcc (mingw or cygwin in windows). Turbo c is an extinct compiler, somewhat hopelessly outdated, and you cannot find libraries for it etc. Otherwise, using conio is perfectly ok, there is conio for windows, and there is also conio for linux, so we may say it's a cross-platform library, and at that very easy to implement. There are really no better alternatives for windows, because windows console is so primitive that it cannot accept ansi terminal escape sequences. And it doesn't make sense to learn curses, as today it doesn't make sense any more to write user interfaces in text mode, but gui is a bit too complicated for the most simple programs.

TkTkorrovi 69 Junior Poster

Yes i know about agar, there are also several other graphics libraries which are built on opengl. Opengl is a cross-platform library itself, therefore anything built on it is also cross-platform... But, when i last looked agar, it was still kind of half thing, maybe they finished it now... But, none of these libraries is very widespread, and the reason is that who use opengl or sdl, is mostly interested only in games, and not in any gui... And also these who already use some gui library, are not interested in any game libraries such as sdl and opengl... Therefore, such libraries have not much users, so also cannot be expected that they would be well-developed, and so such library can hardly ever be any universal solution... Well and, it would also not be considered a serious solution... This is why i also didn't start to use agar, but use gtk, which is widely used and the most free of such...

TkTkorrovi 69 Junior Poster

> MINGW
The second suggestion is to use a native compiler, not one which has a bloated compatibility layer to make it more Unix-like.

I see that we can never agree, and i have already an experience that it makes no sense to argue, because there would be no rational explanations. By you, visual basic is then much better than c, because not only the compiler, but all the language, is made only for one operating system.

Yes it's right that compatibility layer may make certain system functions slower, on the same reason it may make all programs in a certain language slower, though this compatibility layer is very thin, and there should not be a big difference. But concerning that test, this is not a right way to benchmark a programming language. The benchmarking loop should not contain the system functions necessary for benchmarking. Instead, the program should go through some fixed number of iterations, which preferrably contain many different operations, and the time spent for running that loop should be measured. Then the benchmark would show more the speed of the programming language, and not the speed of the system functions.

TkTkorrovi 69 Junior Poster

graphics.h is a turbo c header, turbo c is an old commercial compiler which is not maintained any more, there is no practical use of such compiler. Try not to learn useless things, use cross-platform compiler like gcc, this would never go out of use. These are the GTK drawing functions http://developer.gnome.org/doc/API/2.0/gdk/gdk-Drawing-Primitives.html This is a very simpel drawing kit as well. If you want to do some more advanced drawing, like gradients, antialiased drawing etc, then you should use something more advanced, like libcairo. If all you are ever going to do, is writing games, use SDL, or even better opengl if these have to be 3d games. But even then when there once should be menus and dialog boxes in your game, a full GUI like GTK might still be better.

TkTkorrovi 69 Junior Poster

OK, to be more exact, and i must be very exact, Qt is developed by Trolltech, but wxwidgets knowingly not by any company. But licenses of both are not a clear LGPL, which is the license of GTK... Also, wxwidgets is for c++, so both of them are not alternatives for these who want to use c. And considring that this forum is about c, there are so far no other cross-platform GUI libraries to choose, than GTK... Still there are likely others, but these are then not much widespread at all. One may say there is SDL, but this is only a graphics library, with no GUI (though there is one which would hardly ever satisfy anyone), and even no windows, this is certainly not something even close to a universal graphics library...

TkTkorrovi 69 Junior Poster

To control hardware, in general, you have to write a device driver, if of course there is no existing driver for your device, which satisfies your needs. Because the hardware devices cannot be accessed from user space, but only from kernel space. This is the classic book about writing linux device drivers http://lwn.net/Kernel/LDD3 It is likely much more difficult to control hardware in Windows, because all the kernel code is available in Linux, but only a restricted amount of information is available in Windows...

TkTkorrovi 69 Junior Poster

Yes, $10/hour, and first 8 hours $50 additional, would be OK for me :)

But seriously, use fgets, not scanf, for input.

TkTkorrovi 69 Junior Poster

The biggest advantage of GTK over QT and wxwidgets is that GTK is *non-commercial*, which means the most free, and the least problems with licenses also when developing the commercial applications. Therefore GTK is the best joice, it is also much more widespread than wxwidgets, and wxwidgets as much as i know, is not a completely independent api, but makes you to use features from the platform where you compile. QT is also only for c++, while GTK is for c, and can therefore be used both from c and c++. Otherwise GTK and QT are very similar.

TkTkorrovi 69 Junior Poster

Ohh, mistake in the title, can someone repair it? To make things easier for you, proceed like this:

1. Download mingw at http://downloads.sourceforge.net/mingw/MinGW-5.1.3.exe?modtime=1168811236&big_mirror=1 and install it in the directory /mingw

2. Download msys at http://downloads.sourceforge.net/mingw/MSYS-1.0.10.exe?modtime=1079444447&big_mirror=1 and install it, saying that mingw is installed in /mingw

3. Download unzip at ftp://ftp.info-zip.org/pub/infozip/WIN32/unz552xn.exe and ftp://ftp.info-zip.org/pub/infozip/WIN32/unz552dn.zip and install it in /mingw/bin

4. Download wget at http://users.ugent.be/~bpuype/cgi-bin/fetch.pl?dl=wget/wget.exe and install it in /mingw/bin

5. Add /mingw/bin to PATH

6. Create a text file called list in your /mingw directory, and add the following list there:

http://ftp.gnome.org/pub/gnome/binaries/win32/atk/1.12/atk-1.12.3.zip
http://ftp.gnome.org/pub/gnome/binaries/win32/atk/1.12/atk-dev-1.12.3.zip
http://www.gimp.org/%7Etml/gimp/win32/gettext-0.14.5.zip
http://www.gimp.org/%7Etml/gimp/win32/gettext-dev-0.14.5.zip
http://ftp.gnome.org/pub/gnome/binaries/win32/glib/2.12/glib-2.12.13.zip
http://ftp.gnome.org/pub/gnome/binaries/win32/glib/2.12/glib-dev-2.12.13.zip
http://ftp.gnome.org/pub/gnome/binaries/win32/gtk+/2.10/gtk+-2.10.14.zip
http://ftp.gnome.org/pub/gnome/binaries/win32/gtk+/2.10/gtk+-dev-2.10.14.zip
http://gnuwin32.sourceforge.net/downlinks/jpeg-bin-zip.php
http://gnuwin32.sourceforge.net/downlinks/jpeg-lib-zip.php
http://www.gimp.org/%7Etml/gimp/win32/libiconv-1.9.1.bin.woe32.zip
http://gnuwin32.sourceforge.net/downlinks/libpng-bin-zip.php
http://gnuwin32.sourceforge.net/downlinks/libpng-lib-zip.php
http://ftp.gnome.org/pub/gnome/binaries/win32/pango/1.16/pango-1.16.4.zip
http://ftp.gnome.org/pub/gnome/binaries/win32/pango/1.16/pango-dev-1.16.4.zip
http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/cairo-1.4.8.zip
http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/cairo-dev-1.4.8.zip
http://www.gimp.org/%7Etml/gimp/win32/pkg-config-0.20.zip
http://gnuwin32.sourceforge.net/downlinks/tiff-bin-zip.php
http://gnuwin32.sourceforge.net/downlinks/tiff-lib-zip.php
http://www.zlib.net/zlib123-dll.zip

7. Make sure that you are in the directory /mingw, the only reasonable way to do that, is going there with windows cmd shell, remember that windows explorer doesn't change directory in the shell!

8. Run wget -i list

9. Run unzip *.zip

10. Open msys, go to the directory where your code is, use absolute path while changing directory if necessary, and compile.

That's all :)

TkTkorrovi 69 Junior Poster

fclose is all you need to free a file pointer. About your pFile pointing still to the same place... pFile is just a variable, and no function can change its value, unless you give it as &pFile as argument, in which case that function should expect pointer to pointer as argument. Freeing memory affects the memory block allocated, but doesn't change the pointer which you used to point to the allocated memory.

TkTkorrovi 69 Junior Poster

I created this thread to have a common place to discuss these issues. GTK is a cross-platform non-commercial graphical user interface for C, now there are these snippets here using GTK http://www.daniweb.com/code/snippet744.html and http://www.daniweb.com/code/snippet737.html but i hope that there would be more :)

Maybe the best howto is this http://www.ibiblio.org/apollo/WinGtkHowto.html I though don't recommend using glade. Also, there is an easier way to compile GTK programs:

gcc something.c -o something.exe -std=c89 -Wall `pkg-config gtk+-2.0 --cflags --libs`

It is again because of the braindead nature of many windows things, that the pkg-config part between the backquotes must be last in command line, though in gcc it doesn't suppose to matter where in the command line something is. You can also write a simple makefile:

all:
	/mingw/bin/redir -e errors.txt gcc something.c -o something.exe -std=c89 -Wall `pkg-config gtk+-2.0 --cflags --libs`

and then run "make" in the directory where your code is, to compile. There, the redir stuff is just to redirect the errors to errors.txt, you can do without it, but it's useful sometimes. The reason why the msys is necessary, is because of the braindead nature of windows things, as well. It is just that the windows shell cannot anyhow do the simple thing what these backquotes mean, ie to add the output of the command in backquotes, to command line. Instead of msys you may also use z shell http://zsh.dotsrc.org in windows. Other good feature of the bash-like shell is …

TkTkorrovi 69 Junior Poster

Yes delay is necessary, because it gives time to the rest of the system and other programs, when your program doesn't need it. A delay less than 10 milliseconds (10 000 microseconds) makes no sense, and is never accurate, because the minimum amount of time which scheduler gives to a program, is 5 milliseconds. usleep is defined in unistd.h, and implements delay in microseconds. But the problem is that not every system has unistd.h, also this header is not available when we use strict standard c. Therefore it's better to use select in sys/select.h for delay, delay is implemented in that way in GTK Asteroids http://www.daniweb.com/code/snippet744.html There is also a function g_usleep in GTK glib. But when one uses mingw in windows, then the only delay which is implemented in mingw, is _sleep in stdlib.h, which again is not available in strict standard c, also g_usleep in GTK should work in windows.

Notice that none of these functions are part of the standard c, usleep and select are part of the POSIX standard, and g_usleep is part of the GTK, _sleep in stdlib.h is only the mingw addition, sleep in time.h is also a non-standard addition in a few compilers.

TkTkorrovi 69 Junior Poster

I don't know, in general, c doesn't guarantee really much concerning the exact layout of the structure in memory. So, using memcpy for structures, is likely not so good idea... The only good way to copy structures in c, is member by member. Therefore certainly, if something can be implemented as a multidimensional array, then it should be done so, all the copying and writing would be easier then.

TkTkorrovi 69 Junior Poster

For such things, look sometimes at freashmeat or SourceForge, there are many c programs, you likely can find there examples about whatever you are going to do. For example, Simple Generic Assembler http://sourceforge.net/projects/sgasm This is a very simple assembler, seemingly made also without yacc or bison, written in c.

TkTkorrovi 69 Junior Poster

Read this, especially FAQ http://www.linux-usb.org. You can run your program after the device is plugged in, using the hotplug script.

TkTkorrovi 69 Junior Poster

Look, the c compilers are made to be fast, there are compilers which use only one pass for finding all the symbols. Now you call your "square" function before you define or declare your function, so the compiler knows nothing about your function when it processes your function call. So you either have to define your function before, or provide a prototype. The latter is especially useful, because you later may want to make your function available to other modules, by include file. As this is so necessary, to declare what functions you would like to make available to the rest of the program, and what not, this is because any more complicated search for function names is not necessary in c. Because it is a good habbit to write function prototypes, and makes the code much clearer.

And, don't make Salem angry with void main, there is a purpose for main to be int, and this has something to do with the rest of your system. When some "simpler" languages maybe are not made to work together with other programs, then c has been used all the time to write all the components of the system, and there, the program is not a stand-alone unit, but has to work together with other programs. The program would not always run separately, but can be used in a shell script as a part of some more complicated processing, or executed from inside of some other program.

TkTkorrovi 69 Junior Poster

I'm sorry for replying so late, but i couldn't explain more before, because there were not much programming examples for such graphics games. Now i made one and posted here in snippets, a GTK version of the original xasteroids (which was written with xlib) http://www.daniweb.com/code/snippet744.html

In addition to keyboard input etc, you see there, that a frame is prepared in every game loop, and then the expose event would be ordered to write the frame on window. The frame is made in pixbuf, which is nothing else than a picture in memory, the pixbufs can be copied into each other, modified in various ways, and loaded from image files of different formats, or embedded into the code as strings. There is also a thorough collision and bouncing implemented, this could though be a simpler one for the round objects such as asteroids, but it could be good for the objects with less round shape, so maybe that too would be useful for you when writing a cricket game, or for anyone who wants to write a similar game.

As i said earlier, GTK is a good thing to use, if you are not going to write 3d games, because GTK is free, not anyhow commercial, and truly cross-platform, and it's useful to learn it because it is also a good api to write graphical user interfaces, such as various dialog boxes and menus, the gnome desktop and many other important applications were made with it. Therefore …