Wednesday, September 24, 2008

C...Learning: Chapter 7 of 8 "Access to stored Data"

There is a lot of stuff about this chapter.

I've learned how to create and write a file and how to read a file

On this, I've made for practice a programm that stores Personal data ( Name, Surname, Age) in structures (specified N) and afterwards it creates a file and stores those data. Then it gives you the option to retrieve the data (read the file) you stored and show it in the screen. Practical exercises like this are of the most importance but they take much time

After these 2 elements I've red about :
temporary files creation
binary files (didnt got much)
data rapprochement (didnt payed much attention)

However I didnt tested pratically these elements

I'm proceeding to the final chapter, Chapter 8 "Standar Library"

P.S.
God! I know most parts of C theoritically while ohters (e.g. dynamic memory manipulating) I didnt learned them at all!
When I'm gonna to write C on practice, its gonna be the mess!

Actually, I'll be heading to API (which works on C) after chapter 8 from a 400 pages book probably. I hope I will exercise there a bit otherwise I'll have to exercise all 3 languages learned in the end while programmingGames from the targeted book (Beginning Game Programming)

Monday, September 22, 2008

C...learning: Chapter 6 of 8 "Structures"

I've left the dynamic memory manipulating. Its not the firs in priority. Later it may be but not now. I'll proceed to chapter 7

Saturday, September 20, 2008

C...learning: Chapter 6 of 8 "Structures"

Here we have with a master piece part!
From what I can get its usefull for creating databases forms but I'll have to ask for it
answer: yes thats an example of its usance

It was a very productive day. I believe that these will be very usefull in game programming where you will have tens of elements with properties (enemies, objects etc...)

Now set a closer look upon structures...

A structure - the way I see it of course - is an object, more like a box in which you can store elements (variables). Once created, it contains the variables (charactersitcs) of your project and you can call those separately to appear.

Doesn't it reminds an Array? If we have an Array for storing several elements, why shall we have a structure?

It gives you the ability to create databases. I've created a structure "User" which contained Name,Surname,Age and I've put 10 of this structures into a 10 size array.

So now each cell contained all 3 types a user's informations (Name,Surname,Age)

If there werent structures I would have to create 3 arrays and jumping like a Kangaroo from array to array.

So structures are like folders. You put inside them all informations about their element and you store them (all the folders) into a drawer (array) with a characterstical name on each folder to be able at any time to lift it and imediately access all of its informations-elements. I've created this image

C...learning: Chapter 5 of 8 "Preproccessor"

Nothing complex but I can't get its usance still. However I'm sure when I will programm games from the book, I will...

As I saw it its a like a way for replacing pieces of codes or value with your custom texts, but it go even further.

It gives you the ability to make choice structures with if for the pieces you,ve set.

So since its above any function or command its like having 2 different ways in the program flow, on the one hand being into a complex while statement in some function and in the meantime continuing giving several orders with the preprocessor, orders that affect other parts of the program (or the whole program) despite the fact that you re narrowed to a while statement.

Thursday, September 18, 2008

C...learning: Chapter 4 of 8 "Functions"

I've used simple functions handling -without variables passing- hundreds of time in C++ and so I just viewed the introductive parts.

I still can't fully get the usance of "Categories of Saving Variables" (extern,static,auto,register ) and specifically the extern but I think I will lately with "files direction"

Now the issues about pointers in functions. The first notable of the chapter
float z = 3
float* const pointer= &z
you can change the contect (*const pointer=5;) and not the adress (const pointer = &a;)

const float * pointer=&z;

you can change the adress but not the content.
However you can change the variable of the adress.
So this is the way for changing the content in this case

If you want to completely lock both pointer and the variable then you have to do this


About references its the way to pass the adresses from variables of a function to another functions. But from the time the function has the adresses, nothing stops her to change their content. So its the way for changing the variables passed to other functions.

Now, about the form of this process we have the example

main()
{ int x=5, y=10;
function (&x, &y); ...}

void function (int* x, int*y)
{ *x=0;
*y=0; }

You declare pointers in the function and so you pass them the adresses. Now you have the power to change them

When you're passing an array, you just pass its adress so you can either pass the array's name, or a pointer - for an arrays name its actually an adress of the array

You have also the ability to pass pointers.

Therefore you can even make a function call itself - flashback (anadromh in Greek)!

C...learning: Chapter 3 of 8 - Left 2ond Part "Arrays and Pointers"

I have to admit that the 2ond part of chapter 3 reffering to pointers usance in arrays was difficult. I couldn't get the usance of all those things.

I won't be losing time. If there is something from those elements that will be used in the book for Game Programming I will mind then but now these things may be of little use for there and so I won't be losing time learning them.

I will proceed to chapter 4 "Functions"

P.S.
During my experiments with arrays I've learned some new things about the "%" operator and for.
This operator does not declare the end of the text to set a numbe but rather it can;t be set between text as it declares the position within text where the variable -that is declared after the brackets- is going to be set.

So when you want to put 2 variables between the text you do this
printf ("Cell %d is %d",i, matrix1[i]);

and not what I've first tried
printf ("Cell %d",i,"is%d",matrix1[i]);

Now what I've discovered about for is that after the parentesis if you put ";" then its like having an empty statement (having nothing between the brackets "{}")

Another great thanks to the forums

Sunday, September 14, 2008

C...learning : Chapter 3 of 8 "Arrays"

Yesterday I've entered the 3rd chapters which is about matrixes and pointers.

I've red the 1st part reffering only to matrixes and now I'm experimenting with some test before i proceed to the 2ond part.

Wednesday, September 10, 2008

Blog News : Blog's Header Image

I wanted to give a special and more artistic look to the blog, and so I've created this image on photoshop. I would like you to rate it.

Once you Vote it you may post your comments in this post.

Monday, September 8, 2008

C...learning: Chapter 2 of 8 "Control Commands"

Well Yesterday Proceeded to the 2ond chapter "Control Commands". Which included if, if-else, switch, while, do-while, for, continue, return, goto, exit()

It was a quick look more likely since i know most of them from my short C++ experience.

In switch however there is the difference that in the end, you have "default()" rather than "else".

The triple operand was something new to me, but despite the initial complexity I got it. A well shrinked form of if-else but which on first look I think has restricted capabilities - only variables checking - and so I dont think I will be using it much.

edit After Project was Back Online

-------------------------------------------------------------------------
This is an image showing the nature of the triple operand. With the experience of a Project like battleship i came up that it can come usefull in saving you tons of code.





-----------------------------------------------------------------------------

Continue and exit() were new to me too despite tehy existed in C++.

The for form in Confused me with the initialization command. I didnt remembered it. The basic form means

Form Expalnation

//-----------------------------------------------------------------------------------------------

for (a=0/*assign 0 to a*/; a>0/*while a>0*/,a++/*repeat (while a>0)*/)

//-----------------------------------------------------------------------------------------------

Appears idiot to be found there an initialization function and thats why I was confused

I had also some issues with return(). I couldnt understand why it was termintaing my programms in main despite I wasnt putting "return 0"

printf("Start. Give a\n");
scanf("%d",&a);
printf("\na is %d\n",a);
if (a==2)
{
return a;
printf("a is 2\n");
}
return 0;


Well thanks to the forums I've cleared up things.

"If you are in main(), the runtime library has called main() function. In the case of Windows, the routine that calls main () is mainCRTStartup() ). So using return; within main just goes back to mainCRTStartup(). mainCRTStartup() returns to kernel32.dll which terminates your program.

In other words, in all cases, return; only returns from a function. It is not what terminates the program--the only thing that can is the OS
."

"The return keyword calls the end of a function that has a return value. So if you had a different function that returned the length of a string, for instance, you would not leave that function until you reached a return statement or else some exception occurred and you went out of the functions scope. So when they say that it returns control to the main function it means its then end of the previous function. It does not output the value of two to the screen because that would require a specified output stream and no it does not work like the break keyword."

example

#include
using namespace std;

float add (float x, float y) // a simple addition function
{
//---------------------------------\/HERE\/-----------------------------
return x + y;
// this will return to wherever it was called from//<---
//---------------------------------/\HERE/\-------------------------------
}

int main ()
{
float t = add (4.33f, 299.3f);
return EXIT_SUCCESS; // nowhere to return from, so we exit
}

So basicaly its usance is to pass values back in the "mother functions" for asignation of variables from another function

Saturday, September 6, 2008

C...learning: Cleared up printf and the "%" operator

Finally I've managed to cover my empty spaces about this 2 elements of C.

In the printf fuction before outputing a value you have to declare its kind in the brackets ("...") by using the % symbol in the brackets followed by the type the value is gonna be (decima,float,char) 

C does not support the cout function from C++ as an older language.

"C does not have overload operators, so there is only one printf fuction that accepts any number of parameters - type of the passed parameter is not known to the function.
to get the function some idea - how it should interpreter the passed parameters - format specifiers are used, each format specifier starts with %
"

Also I couldnt understand how precision works in printf (%x.xf). The right part was  cuting numbers but the left part  seemed to do nothing

But as found at MSDN library

"...If width is prefixed with 0, zeros are added until the minimum width is reached (not useful for left-aligned numbers)."

There was finally another wonder. I couldn't find why someone would use the hexademical system for variables? Finally someone told me that there could be 3 reasons for that

"1st off you are required to have a hex editor to read the file (when looking at a hex file through notepad or th elike it will just be jumbled text).

2ond, you can store all values between 0 and 255 in 2 characters instead of 3, which can cut down on the number of characters you need and thus the file size when you are programming say a game where inventory and things can be changed and have nultiple values.

3rd, it really doesn't matter to the C/C++ compiler. Both use a base 2 (Binary) system for numeric calculations so it has to convert anyway, base 16 (Hex) compared to base 10 (Decimal) isn't very different after being converted to base 2."

I admit that I can't fully understand all of the reasons wright now nor apllicate the reasons. But just this knowledge is enough for now.

Well, by the present facts and calculations, I  think that I can proceed to the 2nd of 8 chapter which is about the "Control Commands" (if,else...). Probably I will be finishing it rather quickly as I know most of the functions from C++ but never swear on these things.



C...learning: 1st Day (4-9-08)

Well the day before-yesterday at 4th September, I've learned the basics of C by reading the 1st from the 8 chapters my 290pages book includes.

Constants, Variables, using of the "%" operator, basic of pointers, the printf, scanf functions.

Mostly i was familiar with the staff from my C++ programming experience, yet I found difficulties

The Nature of Pointers

I was confused because I couldn't declare the pointer wright to the Variable bu just to its refference

int x=5;int y=5;int* pointer=&y;

printf(" x is, %d\n",x);
printf(" y is, %d\n",y);
printf(" &y is, %d\n",&y);
printf(" pointer is, %d\n",pointer);
printf(" *pointer is, %d\n",*pointer);
printf(" &*pointer is, %d\n",&*pointer);

scanf("a");
return 0;

OUTPUT

x is, 5
y is, 5
&y is, 2293604
pointer is, 2293604
*pointer is, 5
&*pointer is, 2293604

But by asking on the forums, until yesterday I've cleared up things as I learned that a pointer its by word an adress and so can only be assigned to an adress.

   P.S. Was confused until I 've outputed the pointer itself "printf(" pointer is, %d\n",pointer);"

However the "*" symbol is nothing more than a guidline to force the pointer show the content of its adress

And the "&" symbol on the contrary forces the revealance of the adress of a variable.

The Fact that when you were outputing "&*pointer" you were getting the adress confused me.

"Why do that?! The pointer is an adress itself!"

But what I've understood quickly was that when you had "*pointer" since the "*" forces teh content revealance, it is like having the variable itself (at least thats the way i saw it), and so, when you put a "&" in front of "*pointer" its like putting it in front of the variable, so you get the adress.

I've created this image to have a schematical reprsentation in my mind

Well I believe it was good I've cleared absolutely this basic fact in the initials of pointers. Empty spaces like this can be dreadfull later. I've experienced that with classes on C++

Well before I proceed to the next chapter I want to clear up things with the "%" operator and the scanf function.

These two especially the % confused me too. Lets hope I'm gonna clear things the same.

The Beggining

I was always interested in Game Programming and thats the reason for now beggining learning C. See a book I own which puts you on the path for creating simple 2D games works with C, DireXt and Windows Programming (API) languages, and also with Multimedia Creation Programms (Audio Editing, 3D Animating) but I already have a basic experience on that sector (The Blog's Header Image is My Creation, Done some 3D Animations too ) So currently I'm learning the grammar and syntax of C then I think i will be heading to Windows Programming (PowerShell)