Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: how to break this code into: a deader file .h,implementation file .c  (Read 770 times)

0 Members and 1 Guest are viewing this topic.

Spartacus

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
I need to break this code into three pieces. Header file .h,  implementation file .c and the main file.
Thank you.

//include directive
#include <stdio.h>
#include <SFML/Graphics.h>


int main(void)
{
   
    // change the size of the window
    sfVideoMode mode = {200, 300, 32};
    sfRenderWindow* window;
    sfCircleShape* circle;
    sfSprite* sprite;
    sfEvent event;
   
    // allocates memory
    window = sfRenderWindow_create(mode, "Olti Asllanaj", sfResize | sfClose, NULL);
    if (!window)
        return 1;
   
    //create a circle to display
    circle = sfCircleShape_create();
    if(!circle)
        return 1;
   
    //changes the radius of the circle
    sfCircleShape_setRadius(circle, 100);
    //changes the color of the cicrcle
    sfCircleShape_setFillColor(circle, sfRed);
   
    // checks if the window is open
    while (sfRenderWindow_isOpen(window))
    {
       
        while (sfRenderWindow_pollEvent(window, &event))
        {
            // close window: exit
            if (event.type == sfEvtClosed)
                sfRenderWindow_close(window);
        }
       
        // Clear screen and change the color of the window
        sfRenderWindow_clear(window, sfBlack);
        sfRenderWindow_drawCircleShape(window, circle, NULL);
       
        //displaly window
        sfRenderWindow_display(window);
    }
    //destroy the window and the circle
    sfCircleShape_destroy(circle);
    sfRenderWindow_destroy(window);
   
    return 0;
}

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10846
    • View Profile
    • development blog
    • Email
how to break this code into: a deader file .h,implementation file .c
« Reply #1 on: September 20, 2015, 01:41:55 am »
And why should we do this for you?

If you don't know how header and source files work you better look it up in a good C book.

One way would be to declare a function in a header, but the definition into the source file and call the function from the main source file.

Any reason you use CSFML?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Spartacus

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: how to break this code into: a deader file .h,implementation file .c
« Reply #2 on: September 20, 2015, 01:50:49 am »
I just start it using CSFML in  school. So is completely new for me. Im trying to understand how it works.
Thank you.
« Last Edit: September 20, 2015, 01:54:46 am by Spartacus »

 

anything