xtjacob
April 24th, 2012, 03:54 AM
I am attempting to compile a multi-file program, and I keep getting these errors when attempting to compile it:
main.c: In function ‘button_clicked’:
main.c:10:3: error: too many arguments to function ‘conditions’
main.c:3:5: note: declared here
main.c: In function ‘main’:
main.c:62:1: error: expected ‘;’ before ‘}’ token
Here is what I am compiling with:
gcc -Wall -lcurl -l json parser.c fileread.c sparser.c conditions.c `pkg-config --cflags gtk+-3.0` main.c `pkg-config --libs gtk+-3.0`
I'm not sure why I'm getting this error since I have this at the top:
void conditions(char *location);
Main.c:
#include <gtk/gtk.h>
void conditions(char *location);
void button_clicked(GtkButton *button, gpointer *entry1)
{
const gchar *location;
location = gtk_entry_get_text(GTK_ENTRY(entry1));
conditions(location);
}
int main(int argc, char *argv[]) {
GtkWidget *window;
GtkWidget *table;
GtkWidget *label1;
GtkWidget *entry1;
GtkWidget *button;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_title(GTK_WINDOW(window), "GtkEntry");
gtk_container_set_border_width(GTK_CONTAINER(windo w), 10);
table = gtk_table_new(2, 1, FALSE);
gtk_container_add(GTK_CONTAINER(window), table);
label1 = gtk_label_new("Zipcode:");
gtk_table_attach(GTK_TABLE(table), label1, 0, 1, 0, 1, GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 5, 5);
entry1 = gtk_entry_new();
gtk_table_attach(GTK_TABLE(table), entry1, 1, 2, 0, 1, GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 5, 5);
button = gtk_button_new_with_label("Enter");
gtk_table_attach_defaults(GTK_TABLE(table), button, 2, 3, 0, 1 );
gtk_widget_show(table);
gtk_widget_show(label1);
gtk_widget_show(entry1);
gtk_widget_show(button);
gtk_widget_show(window);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
g_signal_connect(GTK_BUTTON(button), "clicked", G_CALLBACK(button_clicked), entry1);
gtk_main();
return 0;
}
conditions.c:
/************************************************** ***********
* Copyright 2012 *
* Jacob Boline *
************************************************** ***********/
#include <stdio.h>
#include <curl/curl.h>
#include <string.h>
#include <stdlib.h>
#include <json/json.h>
#include <math.h>
void curlf(const char* url);
const char* fname = "conditions.json";
const char* sfname = "settings.json";
char* json_parse(json_object * jobj, char const *stemp);
char* json_sparse(json_object * jobj, char const *stemp);
char* file_read (const char* filename);
void conditions(char *location);
void conditions(char *location)
{
char *temp;
char *dpnt;
char *rhum;
char *wind;
char *pressure;
char *trend;
char *metric;
char *windir;
//char location[5];
char url[150] = "http://api.wunderground.com/api/59eb6f72cabe560e/conditions/q/"; /*Declares inital URL*/
char const *srhum = "relative_humidity";
char const *swind = "wind_mph";
char const *spressure = "pressure_in";
char const *strend = "pressure_trend";
char const *smetric = "use_metric";
char const *swindir = "wind_dir";
char stemp[10] = "temp_";
char sdpnt[10] = "dewpoint_";
strcat(url, location); /* Appends location to URL. */
strcat(url, ".json");
curlf(url); /* Calls cURL function. */
//printf("File downloaded.\n");
char* sfile = file_read(sfname); //Opens settings file
if (sfile)
{
json_object* jobj = json_tokener_parse(sfile); /* Sets parsing paramaters. */
metric = json_sparse(jobj, smetric); /* Parses for settings */
free(sfile); /* release allocated memory */
}
if (strcmp(metric, "0") == 0)
{
strcat(stemp, "f");
strcat(sdpnt, "f");
}
if (strcmp(metric, "1") == 0)
{
strcat(stemp, "c");
strcat(sdpnt, "c");
}
char* file = file_read(fname);
if (file)
{
json_object* jobj = json_tokener_parse(file); /* Sets parsing paramaters. */
temp = json_parse(jobj, stemp); /* Parses for temperature (f) */
dpnt = json_parse(jobj, sdpnt); /* Parses for Dewpoint (f) */
rhum = json_parse(jobj, srhum); /* Parses for relative humidity */
wind = json_parse(jobj, swind); /* Parses for wind info */
pressure = json_parse(jobj, spressure); /* Parses for pressure (in) */
trend = json_parse(jobj, strend); /* Parses for pressure trend */
windir = json_parse(jobj, swindir);
free(file); /* release allocated memory */
}
if (strcmp(metric, "1") == 0)
{
printf("The temperature is %s degrees celcius.\n", temp);
printf("The dewpoint is %s degrees celcius.\n", dpnt);
}
if (strcmp(metric, "0") == 0)
{
printf("The temperature is %s degrees fahrenheit.\n", temp);
printf("The dewpoint is %s degrees fahrenheit.\n", dpnt);
}
printf("Relative Humidity is %s.\n", rhum);
printf("Wind is %s mph %s.\n", wind, windir);
if (strcmp(trend, "+") == 0)
{
printf("Pressure is %s in and increasing.\n", pressure);
}
if (strcmp(trend, "0") == 0)
{
printf("Pressure is %s in and constant.\n", pressure);
}
if (strcmp(trend, "-") == 0)
{
printf("Pressure is %s in and decreasing.\n", pressure);
}
}
void curlf(const char* url)
{
CURL *json;
FILE *wdata;
json = curl_easy_init(); /* Start downloading process. */
curl_easy_setopt(json, CURLOPT_URL, url); /* Tells cURL what the URL is. */
wdata = fopen(fname, "w"); /* Create file to save data. */
curl_easy_setopt(json, CURLOPT_WRITEDATA, wdata); /* Tells cURL to save sata to wdata. */
curl_easy_perform(json); /* Performs download. */
curl_easy_cleanup(json); /* Cleans up. */
fclose(wdata); /* Close file. */
}
Any help would much appreciated!
main.c: In function ‘button_clicked’:
main.c:10:3: error: too many arguments to function ‘conditions’
main.c:3:5: note: declared here
main.c: In function ‘main’:
main.c:62:1: error: expected ‘;’ before ‘}’ token
Here is what I am compiling with:
gcc -Wall -lcurl -l json parser.c fileread.c sparser.c conditions.c `pkg-config --cflags gtk+-3.0` main.c `pkg-config --libs gtk+-3.0`
I'm not sure why I'm getting this error since I have this at the top:
void conditions(char *location);
Main.c:
#include <gtk/gtk.h>
void conditions(char *location);
void button_clicked(GtkButton *button, gpointer *entry1)
{
const gchar *location;
location = gtk_entry_get_text(GTK_ENTRY(entry1));
conditions(location);
}
int main(int argc, char *argv[]) {
GtkWidget *window;
GtkWidget *table;
GtkWidget *label1;
GtkWidget *entry1;
GtkWidget *button;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_title(GTK_WINDOW(window), "GtkEntry");
gtk_container_set_border_width(GTK_CONTAINER(windo w), 10);
table = gtk_table_new(2, 1, FALSE);
gtk_container_add(GTK_CONTAINER(window), table);
label1 = gtk_label_new("Zipcode:");
gtk_table_attach(GTK_TABLE(table), label1, 0, 1, 0, 1, GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 5, 5);
entry1 = gtk_entry_new();
gtk_table_attach(GTK_TABLE(table), entry1, 1, 2, 0, 1, GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 5, 5);
button = gtk_button_new_with_label("Enter");
gtk_table_attach_defaults(GTK_TABLE(table), button, 2, 3, 0, 1 );
gtk_widget_show(table);
gtk_widget_show(label1);
gtk_widget_show(entry1);
gtk_widget_show(button);
gtk_widget_show(window);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
g_signal_connect(GTK_BUTTON(button), "clicked", G_CALLBACK(button_clicked), entry1);
gtk_main();
return 0;
}
conditions.c:
/************************************************** ***********
* Copyright 2012 *
* Jacob Boline *
************************************************** ***********/
#include <stdio.h>
#include <curl/curl.h>
#include <string.h>
#include <stdlib.h>
#include <json/json.h>
#include <math.h>
void curlf(const char* url);
const char* fname = "conditions.json";
const char* sfname = "settings.json";
char* json_parse(json_object * jobj, char const *stemp);
char* json_sparse(json_object * jobj, char const *stemp);
char* file_read (const char* filename);
void conditions(char *location);
void conditions(char *location)
{
char *temp;
char *dpnt;
char *rhum;
char *wind;
char *pressure;
char *trend;
char *metric;
char *windir;
//char location[5];
char url[150] = "http://api.wunderground.com/api/59eb6f72cabe560e/conditions/q/"; /*Declares inital URL*/
char const *srhum = "relative_humidity";
char const *swind = "wind_mph";
char const *spressure = "pressure_in";
char const *strend = "pressure_trend";
char const *smetric = "use_metric";
char const *swindir = "wind_dir";
char stemp[10] = "temp_";
char sdpnt[10] = "dewpoint_";
strcat(url, location); /* Appends location to URL. */
strcat(url, ".json");
curlf(url); /* Calls cURL function. */
//printf("File downloaded.\n");
char* sfile = file_read(sfname); //Opens settings file
if (sfile)
{
json_object* jobj = json_tokener_parse(sfile); /* Sets parsing paramaters. */
metric = json_sparse(jobj, smetric); /* Parses for settings */
free(sfile); /* release allocated memory */
}
if (strcmp(metric, "0") == 0)
{
strcat(stemp, "f");
strcat(sdpnt, "f");
}
if (strcmp(metric, "1") == 0)
{
strcat(stemp, "c");
strcat(sdpnt, "c");
}
char* file = file_read(fname);
if (file)
{
json_object* jobj = json_tokener_parse(file); /* Sets parsing paramaters. */
temp = json_parse(jobj, stemp); /* Parses for temperature (f) */
dpnt = json_parse(jobj, sdpnt); /* Parses for Dewpoint (f) */
rhum = json_parse(jobj, srhum); /* Parses for relative humidity */
wind = json_parse(jobj, swind); /* Parses for wind info */
pressure = json_parse(jobj, spressure); /* Parses for pressure (in) */
trend = json_parse(jobj, strend); /* Parses for pressure trend */
windir = json_parse(jobj, swindir);
free(file); /* release allocated memory */
}
if (strcmp(metric, "1") == 0)
{
printf("The temperature is %s degrees celcius.\n", temp);
printf("The dewpoint is %s degrees celcius.\n", dpnt);
}
if (strcmp(metric, "0") == 0)
{
printf("The temperature is %s degrees fahrenheit.\n", temp);
printf("The dewpoint is %s degrees fahrenheit.\n", dpnt);
}
printf("Relative Humidity is %s.\n", rhum);
printf("Wind is %s mph %s.\n", wind, windir);
if (strcmp(trend, "+") == 0)
{
printf("Pressure is %s in and increasing.\n", pressure);
}
if (strcmp(trend, "0") == 0)
{
printf("Pressure is %s in and constant.\n", pressure);
}
if (strcmp(trend, "-") == 0)
{
printf("Pressure is %s in and decreasing.\n", pressure);
}
}
void curlf(const char* url)
{
CURL *json;
FILE *wdata;
json = curl_easy_init(); /* Start downloading process. */
curl_easy_setopt(json, CURLOPT_URL, url); /* Tells cURL what the URL is. */
wdata = fopen(fname, "w"); /* Create file to save data. */
curl_easy_setopt(json, CURLOPT_WRITEDATA, wdata); /* Tells cURL to save sata to wdata. */
curl_easy_perform(json); /* Performs download. */
curl_easy_cleanup(json); /* Cleans up. */
fclose(wdata); /* Close file. */
}
Any help would much appreciated!