Hello all,
I am currently learning C after starting on C++ Anyway I am doing the CS50 CSE hosted on edx, I saw one of the teacher aids using Sublime text 2 on her mac, in turn I downloaded it and I obviously would much rather use it. My drama is getting .h files (from stanford portable library) to work with the program. Now its fair to say I am completely new to integrating something like this, I have tried a number of things but nothing exactly relates to my situation (from what I have found) so nothing is working.
If someone could walk me through this it would be fantastic.
OS X 10.10.3
I have Xcode installed (not sure if it matters)
Sublime Text 2 - 2.0.2
Now this exact same file (.c) works on the virtual OS provided by the CS50 and I am assuming because the compiler has the SPL installed? If thats the case I am not sure how to do this, I saw on a few sites they had some build files? Again above my pay grade and I am desperate to learn.
[code]#include <stdio.h>
#include <string.h>
#include “spl/include/gevents.h”
#include “spl/include/gobjects.h”
#include “spl/include/gwindow.h”
#include “spl/include/ginteractors.h”
int main(void)
{
GWindow window = newGWindow(320, 240);
GButton button = newGButton(“Button”);
setActionCommand(button, “click”);
GOval circle = newGOval(0, 110, 20, 20);
setColor(circle, “BLACK”);
setFilled(circle, true);
add(window, circle);
addToRegion(window, button, “SOUTH”);
double velocity = 2.0;
while(true)
{
move(circle, velocity, 0);
GActionEvent event = waitForEvent(ACTION_EVENT);
if (getEventType(event) == WINDOW_CLOSED)
{
break;
}
if (strcmp(getActionCommand(event), "click") == 0)
{
printf("Clicked\n");
}
if (getX(circle) + getWidth(circle) >= getWidth(window))
{
velocity = -velocity;
}
else if (getX(circle) <= 0)
{
velocity = -velocity;
}
pause(20);
}
return 0;
}[/code]
Error:
[quote]clang: warning: treating ‘c’ input as ‘c++’ when in C++ mode, this behavior is deprecated
In file included from /Users/RyanHudson/Dropbox/Game/game1.c:4:
In file included from /Users/RyanHudson/Dropbox/Game/spl/include/gevents.h:31:
/Users/RyanHudson/Dropbox/Game/spl/include/cslib.h:63:15: error: expected identifier
typedef enum {false, true} bool;
^
/Users/RyanHudson/Dropbox/Game/spl/include/cslib.h:63:22: error: expected identifier
typedef enum {false, true} bool;
^
/Users/RyanHudson/Dropbox/Game/spl/include/cslib.h:63:27: error: expected ‘;’ after enum
typedef enum {false, true} bool;
^
;
/Users/RyanHudson/Dropbox/Game/spl/include/cslib.h:63:1: warning: typedef requires a name -Wmissing-declarations]
typedef enum {false, true} bool;
^~~~~~~
/Users/RyanHudson/Dropbox/Game/spl/include/cslib.h:63:28: warning: declaration does not declare anything -Wmissing-declarations]
typedef enum {false, true} bool;
^~~~
/Users/RyanHudson/Dropbox/Game/game1.c:12:30: warning: conversion from string literal to ‘string’ (aka ‘char *’) is deprecated -Wc++11-compat-deprecated-writable-strings]
GButton button = newGButton(“Button”);
^
/Users/RyanHudson/Dropbox/Game/game1.c:13:27: warning: conversion from string literal to ‘string’ (aka ‘char *’) is deprecated -Wc++11-compat-deprecated-writable-strings]
setActionCommand(button, “click”);
^
/Users/RyanHudson/Dropbox/Game/game1.c:15:19: warning: conversion from string literal to ‘string’ (aka ‘char *’) is deprecated -Wc++11-compat-deprecated-writable-strings]
setColor(circle, “BLACK”);
^
/Users/RyanHudson/Dropbox/Game/game1.c:18:30: warning: conversion from string literal to ‘string’ (aka ‘char *’) is deprecated -Wc++11-compat-deprecated-writable-strings]
addToRegion(window, button, “SOUTH”);
^
6 warnings and 3 errors generated.
[Finished in 2.5s with exit code 1][/quote]
As stated I am new to this, and after hours of stuffing around this is the most promising error I have received because it seems to be the compiler reading C as C++. As I saw the teacher aid running a c program I assume its possible?
Also when I use <> appose to quotes I get the following:
[quote]Dropbox/Game/game1.c:4:10: error: ‘spl/include/gevents.h’ file not found with include; use “quotes” instead
#include <spl/include/gevents.h>
^~~~~~~~~~~~~~~~~~~~~~~[/quote]
But the file is indeed at that location.
Thanks in advance, Ryan