GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Tuesday, March 15, 2011

C - getchar And putchar

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


int main()
{
    system("color 2f");

    char msg;
    msg = getchar();
    putchar(msg);

    return 0;
}

Share/Bookmark

C - gets And malloc

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


int main()
{
    system("color 2f");

    char *msg = malloc(sizeof(char));
    gets(msg);
    printf("%s",&msg);

    // you can also use array of char
    char name[2];
    gets(name);
    puts(name);

    return 0;
}

Share/Bookmark

C - Puts

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


int main()
{
    system("color 2f");

    char apple[] = "Apple be the biggest company now";
    char google[] = "In the future of the time may be Google";
    char zinga[] = "Zinga is another company that has the chance";

    puts(apple);
    puts(google);
    puts(zinga);

    return 0;
}

Share/Bookmark

C - Renaming File

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


int main()
{
    system("color 2f");

    char oldname[] = "lola.txt";
    char newname[] = "lucia.txt";
    int result = rename(oldname, newname);
    if(result == 0){
        puts("Successfull rename");
    }else{
        perror("Error: ");
    }

    return 0;
}

Share/Bookmark

C - Removing File

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


int main()
{
    system("color 2f");

    if(remove("file.txt") == 0){
        perror("Successfully Deleted!");
    }else{
        perror("Error!");
    }

    return 0;
}

Share/Bookmark

Monday, March 14, 2011

CPP - Pointer To Array

For example, you have an array
int age[3]
age[0] = 27;
age[1] = 24;
age[2] = 55;

int *ptr;
ptr = age;
ptr[1] = 88;
cout << ptr[1] << endl;
Share/Bookmark

OpenGL - Vertex Array

Beside vertex arrays, there's also:
GL_COLOR_ARRAY, 
GL_INDEX_ARRAY, 
GL_NORMAL_ARRAY, 
GL_TEXTURE_COORD_ARRAY, and 
GL_EDGE_FLAG_ARRAY

The first is that you call this function for enable the array:
glEnableClientState(GL_VERTEX_ARRAY);

Then you set the data:
static GLint data[] = {
    1, 1,
    3, 3,
    5, 1
};

After finishing it, try
glVertexPointer(2, GLint, 0, data);

Then the last is:
glBegin(GL_TRIANGLES);
    glArrayElement(2);
glEnd();

See more on: http://glprogramming.com/red/chapter02.html
Share/Bookmark