Hi,
I've made some changes to my coding..but unfortunately, there were errors when compiling it..dunno how to solve it..hope anyone can help me...the errors:
client.c: In function senddata:
client.c:147: error: incompatible implicit declaration of function UpdateStatus
client.c:37: error: previous implicit declaration of UpdateStatus was here
The code is as below: -
#include <mysql.h>
-
#include <stdio.h>
-
#include <sys/types.h>
-
#include <sys/socket.h>
-
#include <netinet/in.h>
-
#include <netdb.h>
-
#include <string.h>
-
#include <stdlib.h>
-
-
MYSQL *conn;
-
MYSQL_RES *res;
-
MYSQL_ROW row;
-
-
char *host = "192.168.2.11";
-
char *user = "daily1a";
-
char *password = "daily2006";
-
char *database = "28882db";
-
-
int tbuf;
-
-
void error(char *msg)
-
{
-
perror(msg);
-
exit(0);
-
}
-
-
-
int main(int argc, char *argv[])
-
{
-
-
char string1[500], query[500], transid[50];
-
int i, j;
-
-
void senddata(char* SendString, char* transID);
-
//void senddata(char *SendString, *transID);
-
//void UpdateStatus(char *transID);
-
void UpdateStatus(char transID[100]);
-
void timebuffer();
-
-
conn = mysql_init(NULL);
-
-
j=1;
-
-
while (j=1)
-
{
-
-
/* Connect to database */
-
if (!mysql_real_connect(conn, host,
-
user, password, database, 0, NULL, 0)) {
-
fprintf(stderr, "%s\n", mysql_error(conn));
-
exit(0);
-
}
-
-
/* send SQL query */
-
if (mysql_query(conn, "SELECT TransID, MobileNumber, StartDate, EndDate FROM Subscriptions where Status=0")) {
-
fprintf(stderr, "%s\n", mysql_error(conn));
-
exit(0);
-
}
-
-
res = mysql_use_result(conn);
-
-
-
/* output fields 0, 1 and 2 of each row */
-
while ((row = mysql_fetch_row(res)) != NULL)
-
{
-
if (i==11)
-
{
-
timebuffer();
-
i=1;
-
-
bzero(string1, sizeof(string1)); }
-
else
-
{
-
//transid = row[0];
-
sprintf(string1,"%s,%s,%s,%s", row[0], row[1], row[2], row[3]);
-
printf ("%s\n",string1);
-
senddata(string1, transid);
-
i++;
-
}
-
-
}
-
}
-
/* Release memory used to store results and close connection */
-
mysql_free_result(res);
-
mysql_close(conn);
-
-
return 0;
-
}
-
-
void senddata(char* SendString, char* transID)
-
{
-
-
char buf[8192];
-
//char *update;
-
char message[256];
-
int socket_descriptor;
-
struct sockaddr_in pin;
-
struct hostent *server_host_name;
-
-
char * host_name = "127.0.0.1";
-
int port = 8000;
-
char * str = "A default test string";
-
char * trans = "123456";
-
-
str = SendString;
-
trans = transID;
-
-
if ((server_host_name = gethostbyname(host_name)) == 0) {
-
perror("Error resolving local host\n");
-
exit(1);
-
}
-
-
bzero(&pin, sizeof(pin));
-
pin.sin_family = AF_INET;
-
pin.sin_addr.s_addr = htonl(INADDR_ANY);
-
pin.sin_addr.s_addr = ((struct in_addr *)(server_host_name->h_addr))->s_addr;
-
pin.sin_port = htons(port);
-
-
if ((socket_descriptor = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
-
perror("Error opening socket\n");
-
exit(1);
-
}
-
-
if (connect(socket_descriptor, (void *)&pin, sizeof(pin)) == -1) {
-
perror("Error connecting to socket\n");
-
exit(1);
-
}
-
-
printf("Sending message %s to server...\n", str);
-
-
if (send(socket_descriptor, str, strlen(str), 0) == -1) {
-
perror("Error in send\n");
-
exit(1);
-
}
-
-
printf("...Sent message.. wait for response...\n");
-
-
if (recv(socket_descriptor, buf, 8192, 0) == -1) {
-
perror("Error in receiving response from server\n");
-
exit(1);
-
}
-
-
printf("\nResponse from server:\n\n%s\n", buf);
-
-
UpdateStatus(TransID);
-
//update=buf;
-
//UpdateStatus(update);
-
-
close(socket_descriptor);
-
-
}
-
-
void UpdateStatus(char transID[100])
-
{
-
char query[2000];
-
char query1[2000];
-
char id;
-
char TransID;
-
-
conn = mysql_init(NULL);
-
-
/* Connect to database */
-
if (!mysql_real_connect(conn, host, user, password, database, 0, NULL, 0)) {
-
fprintf(stderr, "%s\n", mysql_error(conn));
-
exit(0);
-
}
-
-
bzero(query1, sizeof(query1));
-
id = atoi(TransID);
-
sprintf(query1, "UPDATE Subscriptions SET Status = 1 WHERE TransID = '%s'",id);
-
-
#ifdef DEBUG
-
printf("%s\n",query1);
-
#endif
-
-
-
/* Release memory used to store results and close connection */
-
mysql_free_result(res);
-
mysql_close(conn);
-
-
}
-
-
-
void timebuffer()
-
{
-
struct timeval tv;
-
-
tv.tv_sec=tbuf;
-
tv.tv_usec=0;
-
-
#ifdef TRACE
-
printf ("time buffer: %d\n", tv.tv_sec);
-
#endif
-
-
select (0,0,0,0,&tv);
-
}
-
Supposedly, this program..after receiving response from server, this client program should update MySQL table.
Thanks
4 3143
Hi,
I've made some changes to my coding..but unfortunately, there were errors when compiling it..dunno how to solve it..hope anyone can help me...the errors:
client.c: In function senddata:
client.c:147: error: incompatible implicit declaration of function UpdateStatus
client.c:37: error: previous implicit declaration of UpdateStatus was here
The code is as below: -
#include <mysql.h>
-
#include <stdio.h>
-
#include <sys/types.h>
-
#include <sys/socket.h>
-
#include <netinet/in.h>
-
#include <netdb.h>
-
#include <string.h>
-
#include <stdlib.h>
-
-
MYSQL *conn;
-
MYSQL_RES *res;
-
MYSQL_ROW row;
-
-
char *host = "192.168.2.11";
-
char *user = "daily1a";
-
char *password = "daily2006";
-
char *database = "28882db";
-
-
int tbuf;
-
-
void error(char *msg)
-
{
-
perror(msg);
-
exit(0);
-
}
-
-
-
int main(int argc, char *argv[])
-
{
-
-
char string1[500], query[500], transid[50];
-
int i, j;
-
-
void senddata(char* SendString, char* transID);
-
//void senddata(char *SendString, *transID);
-
//void UpdateStatus(char *transID);
-
void UpdateStatus(char transID[100]);
-
void timebuffer();
-
-
conn = mysql_init(NULL);
-
-
j=1;
-
-
while (j=1)
-
{
-
-
/* Connect to database */
-
if (!mysql_real_connect(conn, host,
-
user, password, database, 0, NULL, 0)) {
-
fprintf(stderr, "%s\n", mysql_error(conn));
-
exit(0);
-
}
-
-
/* send SQL query */
-
if (mysql_query(conn, "SELECT TransID, MobileNumber, StartDate, EndDate FROM Subscriptions where Status=0")) {
-
fprintf(stderr, "%s\n", mysql_error(conn));
-
exit(0);
-
}
-
-
res = mysql_use_result(conn);
-
-
-
/* output fields 0, 1 and 2 of each row */
-
while ((row = mysql_fetch_row(res)) != NULL)
-
{
-
if (i==11)
-
{
-
timebuffer();
-
i=1;
-
-
bzero(string1, sizeof(string1)); }
-
else
-
{
-
//transid = row[0];
-
sprintf(string1,"%s,%s,%s,%s", row[0], row[1], row[2], row[3]);
-
printf ("%s\n",string1);
-
senddata(string1, transid);
-
i++;
-
}
-
-
}
-
}
-
/* Release memory used to store results and close connection */
-
mysql_free_result(res);
-
mysql_close(conn);
-
-
return 0;
-
}
-
-
void senddata(char* SendString, char* transID)
-
{
-
-
char buf[8192];
-
//char *update;
-
char message[256];
-
int socket_descriptor;
-
struct sockaddr_in pin;
-
struct hostent *server_host_name;
-
-
char * host_name = "127.0.0.1";
-
int port = 8000;
-
char * str = "A default test string";
-
char * trans = "123456";
-
-
str = SendString;
-
trans = transID;
-
-
if ((server_host_name = gethostbyname(host_name)) == 0) {
-
perror("Error resolving local host\n");
-
exit(1);
-
}
-
-
bzero(&pin, sizeof(pin));
-
pin.sin_family = AF_INET;
-
pin.sin_addr.s_addr = htonl(INADDR_ANY);
-
pin.sin_addr.s_addr = ((struct in_addr *)(server_host_name->h_addr))->s_addr;
-
pin.sin_port = htons(port);
-
-
if ((socket_descriptor = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
-
perror("Error opening socket\n");
-
exit(1);
-
}
-
-
if (connect(socket_descriptor, (void *)&pin, sizeof(pin)) == -1) {
-
perror("Error connecting to socket\n");
-
exit(1);
-
}
-
-
printf("Sending message %s to server...\n", str);
-
-
if (send(socket_descriptor, str, strlen(str), 0) == -1) {
-
perror("Error in send\n");
-
exit(1);
-
}
-
-
printf("...Sent message.. wait for response...\n");
-
-
if (recv(socket_descriptor, buf, 8192, 0) == -1) {
-
perror("Error in receiving response from server\n");
-
exit(1);
-
}
-
-
printf("\nResponse from server:\n\n%s\n", buf);
-
-
UpdateStatus(TransID);
-
//update=buf;
-
//UpdateStatus(update);
-
-
close(socket_descriptor);
-
-
}
-
-
void UpdateStatus(char transID[100])
-
{
-
char query[2000];
-
char query1[2000];
-
char id;
-
char TransID;
-
-
conn = mysql_init(NULL);
-
-
/* Connect to database */
-
if (!mysql_real_connect(conn, host, user, password, database, 0, NULL, 0)) {
-
fprintf(stderr, "%s\n", mysql_error(conn));
-
exit(0);
-
}
-
-
bzero(query1, sizeof(query1));
-
id = atoi(TransID);
-
sprintf(query1, "UPDATE Subscriptions SET Status = 1 WHERE TransID = '%s'",id);
-
-
#ifdef DEBUG
-
printf("%s\n",query1);
-
#endif
-
-
-
/* Release memory used to store results and close connection */
-
mysql_free_result(res);
-
mysql_close(conn);
-
-
}
-
-
-
void timebuffer()
-
{
-
struct timeval tv;
-
-
tv.tv_sec=tbuf;
-
tv.tv_usec=0;
-
-
#ifdef TRACE
-
printf ("time buffer: %d\n", tv.tv_sec);
-
#endif
-
-
select (0,0,0,0,&tv);
-
}
-
Supposedly, this program..after receiving response from server, this client program should update MySQL table.
Thanks
The problem is that your function isn't visible until its defined in your source code. You try and call UpdateStatus from senddata, but you don't define the UpdateStatus until after senddata. You either need to rearrange where the order of your functions in your code, or even better is to let the compiler know about the existance of your functions ahead of time using function prototypes. You can either place these prototypes in seperate header file, or at the top of your source file with includes and global data. -
-
// includes and variable declerations
-
-
void senddata(char* SendString, char* transID);
-
void UpdateStatus(char transID[100]);
-
-
// remainder of your code to follow
-
-
Banfa 9,065
Expert Mod 8TB
You have put in function prototypes but you have put them inside main instead of putting them at file scope
Hi All,
I already put the prototypes outside the main and i can compile it but it seems like the UpdateStatus function didnt work at all because it did not update the Status field of table as I query in that function...what's the problem with that function actually?..
Many2 thanks..
-
#include <mysql.h>
-
#include <stdio.h>
-
#include <sys/types.h>
-
#include <sys/socket.h>
-
#include <netinet/in.h>
-
#include <netdb.h>
-
#include <string.h>
-
#include <stdlib.h>
-
-
MYSQL *conn;
-
MYSQL_RES *res;
-
MYSQL_ROW row;
-
-
char *host = "192.168.2.11";
-
char *user = "daily2a";
-
char *password = "daily2006";
-
char *database = "28882db";
-
-
-
int tbuf;
-
-
void senddata(char* SendString, char* transID);
-
void UpdateStatus(char transID[1600]);
-
void timebuffer();
-
-
-
void error(char *msg)
-
{
-
perror(msg);
-
exit(0);
-
}
-
-
-
int main(int argc, char *argv[])
-
{
-
-
char string1[500], query[500], transid[50];
-
int i, j;
-
-
//void senddata(char* SendString, char* transID);
-
//void UpdateStatus(char transID[1600]);
-
//void timebuffer();
-
-
conn = mysql_init(NULL);
-
-
I alter the code something like above. I can compile it but when I run it..I got this kind of message: -
1234567,0192426699,2006-07-17 01:00:00,2006-07-18 00:59:59
-
Sending message 1234567,0192426699,2006-07-17 01:00:00,2006-07-18 00:59:59 to server...
-
...Sent message.. wait for response...
-
-
Response from server:
-
-
1234567,0192426699,2006-07-17 01:00:00,2006-07-18 00:59:59
-
*** glibc detected *** ./test: corrupted double-linked list: 0x08626628 ***
-
======= Backtrace: =========
-
/lib/libc.so.6[0x572e71]
-
/lib/libc.so.6[0x57408d]
-
/lib/libc.so.6(malloc+0x74)[0x575792]
-
/usr/lib/mysql/libmysqlclient.so.14(my_malloc+0x27)[0xa40cc7]
-
/usr/lib/mysql/libmysqlclient.so.14(my_net_init+0x38)[0xa64a88]
-
/usr/lib/mysql/libmysqlclient.so.14(mysql_real_connect+0x150)[0xa60c74]
-
./test[0x8048a74]
-
/lib/libc.so.6(__libc_start_main+0xc6)[0x524de6]
-
./test[0x8048985]
-
======= Memory map: ========
-
00111000-0011a000 r-xp 00000000 fd:00 516149 /lib/libnss_files-2.3.5.so
-
0011a000-0011b000 r-xp 00008000 fd:00 516149 /lib/libnss_files-2.3.5.so
-
0011b000-0011c000 rwxp 00009000 fd:00 516149 /lib/libnss_files-2.3.5.so
-
004ac000-004e1000 r-xp 00000000 fd:00 649001 /lib/libssl.so.0.9.7f
-
004e1000-004e4000 rwxp 00035000 fd:00 649001 /lib/libssl.so.0.9.7f
-
004f2000-0050c000 r-xp 00000000 fd:00 648996 /lib/ld-2.3.5.so
-
0050c000-0050d000 r-xp 00019000 fd:00 648996 /lib/ld-2.3.5.so
-
0050d000-0050e000 rwxp 0001a000 fd:00 648996 /lib/ld-2.3.5.so
-
00510000-00634000 r-xp 00000000 fd:00 648997 /lib/libc-2.3.5.so
-
00634000-00636000 r-xp 00124000 fd:00 648997 /lib/libc-2.3.5.so
-
00636000-00638000 rwxp 00126000 fd:00 648997 /lib/libc-2.3.5.so
-
00638000-0063a000 rwxp 00638000 00:00 0
-
0063c000-0063e000 r-xp 00000000 fd:00 517790 /lib/libdl-2.3.5.so
-
0063e000-0063f000 r-xp 00001000 fd:00 517790 /lib/libdl-2.3.5.so
-
0063f000-00640000 rwxp 00002000 fd:00 517790 /lib/libdl-2.3.5.so
-
00642000-00664000 r-xp 00000000 fd:00 648998 /lib/libm-2.3.5.so
-
00664000-00665000 r-xp 00021000 fd:00 648998 /lib/libm-2.3.5.so
-
00665000-00666000 rwxp 00022000 fd:00 648998 /lib/libm-2.3.5.so
-
00668000-0067a000 r-xp 00000000 fd:00 401321 /usr/lib/libz.so.1.2.2.2
-
0067a000-0067b000 rwxp 00011000 fd:00 401321 /usr/lib/libz.so.1.2.2.2
-
00691000-006a0000 r-xp 00000000 fd:00 516098 /lib/libresolv-2.3.5.so
-
006a0000-006a1000 r-xp 0000e000 fd:00 516098 /lib/libresolv-2.3.5.so
-
006a1000-006a2000 rwxp 0000f000 fd:00 516098 /lib/libresolv-2.3.5.so
-
006a2000-006a4000 rwxp 006a2000 00:00 0
-
0077c000-00785000 r-xp 00000000 fd:00 516127 /lib/libgcc_s-4.0.2-20051126.so.1
-
00785000-00786000 rwxp 00009000 fd:00 516127 /lib/libgcc_s-4.0.2-20051126.so.1
-
0093f000-00940000 r-xp 0093f000 00:00 0
-
009fd000-00a02000 r-xp 00000000 fd:00 649003 /lib/libcrypt-2.3.5.so
-
00a02000-00a03000 r-xp 00004000 fd:00 649003 /lib/libcrypt-2.3.5.so
-
00a03000-00a04000 rwxp 00005000 fd:00 649003 /lib/libcrypt-2.3.5.so
-
00a04000-00a2b000 rwxp 00a04000 00:00 0
-
00a2d000-00a71000 r-xp 00000000 fd:00 582971 /usr/lib/mysql/libmysqlclient.so.14.0.0
-
00a71000-00b37000 rwxp 00044000 fd:00 582971 /usr/lib/mysql/libmysqlclient.so.14.0.0
-
00b37000-00b3a000 rwxp 00b37000 00:00 0
-
00d52000-00d54000 r-xp 00000000 fd:00 648999 /lib/libcom_err.so.2.1
-
00d54000-00d55000 rwxp 00001000 fd:00 648999 /lib/libcom_err.so.2.1
-
00d8d000-00d8f000 r-xp 00000000 fd:00 398328 /usr/lib/libkrb5support.so.0.0
-
00d8f000-00d90000 rwxp 00001000 fd:00 398328 /usr/lib/libkrb5support.so.0.0
-
00d92000-00db5000 r-xp 00000000 fd:00 401325 /usr/lib/libk5crypto.so.3.0
-
00db5000-00db6000 rwxp 00023000 fd:00 401325 /usr/lib/libk5crypto.so.3.0
-
00db8000-00dca000 r-xp 00000000 fd:00 649002 /lib/libnsl-2.3.5.so
-
00dca000-00dcb000 r-xp 00011000 fd:00 649002 /lib/libnsl-2.3.5.so
-
00dcb000-00dcc000 rwxp 00012000 fd:00 649002 /lib/libnsl-2.3.5.so
-
00dcc000-00dce000 rwxp 00dcc000 00:00 0
-
00dd0000-00de6000 r-xp 00000000 fd:00 401327 /usr/lib/libgssapi_krb5.so.2.2
-
00de6000-00de7000 rwxp 00016000 fd:00 401327 /usr/lib/libgssapi_krb5.so.2.2
-
03f9e000-0400d000 r-xp 00000000 fd:00 401326 /usr/lib/libkrb5.so.3.2
-
0400d000-04010000 rwxp 0006e000 fd:00 401326 /usr/lib/libkrb5.so.3.2
-
04012000-0410a000 r-xp 00000000 fd:00 649000 /lib/libcrypto.so.0.9.7f
-
0410a000-0411c000 rwxp 000f8000 fd:00 649000 /lib/libcrypto.so.0.9.7f
-
0411c000-0411f000 rwxp 0411c000 00:00 0
-
08048000-0804a000 r-xp 00000000 08:11 327955 /home/appz/ujie/test
-
0804a000-0804b000 rw-p 00001000 08:11 327955 /home/appz/ujie/test
-
0861d000-0863e000 rw-p 0861d000 00:00 0 [heap]
-
b7e00000-b7e21000 rw-p b7e00000 00:00 0
-
b7e21000-b7f00000 ---p b7e21000 00:00 0
-
b7f70000-b7f74000 rw-p b7f70000 00:00 0
-
b7f85000-b7f87000 rw-p b7f85000 00:00 0
-
bfe71000-bfe87000 rw-p bfe71000 00:00 0 [stack]
-
Aborted
-
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Google Mike |
last post by:
After a lot of thought and research, and playing with FreeTDS and
InlineTDS, as well as various ODBC connections, I have determined that
the fastest and cheapest way to get up and going with PHP on...
|
by: Fraser Hanson |
last post by:
Hello,
I have a table which has a foreign key relationship with itself. I
want and expect my updates to cascade (deletes definitely cascade as
expected) but instead I just get error 1217:...
|
by: Filippo |
last post by:
Hi,
i have a problem about the CLIENT-SERVER architecture procedure.
Well , i have an application in VB with ADO connection to a table in a
database on a SQLSERVER 7.0 .
Is possible to do that...
|
by: MLH |
last post by:
I have a friend with a database application on a web server.
He has invited me to attach to it so I can extract data from
it periodically. I have a few questions...
1) I have a DSL connection to...
|
by: Carlo Tambuatco |
last post by:
I have set up MySQL on my home computer, and I am writing a PHP enabled web
site to run queries on this database.
I have created a database called 'weather' on mysql that I want to access
via my...
|
by: B1ackwater |
last post by:
We've fooled around with Access a bit, but only using the
single-user store-bought version. It seems to be a good
database - versatile and infinitely programmable - and
can apparently be used as a...
|
by: Jobs |
last post by:
Download the JAVA , .NET and SQL Server interview with answers
Download the JAVA , .NET and SQL Server interview sheet and rate
yourself. This will help you judge yourself are you really worth of...
|
by: alex |
last post by:
I've converted a latin1 database I have to utf8. The process has been:
# mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore
--skip-set-charset mydb mydb.sql
# iconv -f...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |