OK! ...Basically, I thought you could return a character array using the prototype char ** methodName() BUT, this doesn't work for my function!!!! Maybe I am doin something very wrong somewhere!!!! ...Well, here is my function......
NOTE: This is a part of my university coursework! It is a coursework to implement a client and server to comply with the coffeepot protocol, HTCPCP!!!
This is the propfind function for my server!!!! ...Its not complete, but I really need to find out how to return the char array "theMessage" to the calling function!!!
There is also a syntax error, but ignore this as all i need to know is how to return the char array!!!!!Code:/***********************************************************************************/ /* FUNCTION TO BUILD A PROPFIND RESPONSE FOR THE CLIENTS PROPFIND REQUEST */ /* RETURNS: A POINTER TO A CHAR ARRAY THAT CONTAINS THE RESPONSE MESSAGE */ /* NOTE: WILL RETURN "NULL" IF THERE WAS AN ERROR IN BUILDING RESPONSE!!! */ /***********************************************************************************/ char ** propfindRequest(char * requestDetail, char * clientIP) { char theMessage[MAXBUFF]; /* VARIABLE TO STORE THE SERVER RESPONSE MESSAGE */ char potNoS[2]; /* STORE THE POT NUMBER IN STRING FORMAT */ int potNo; /* STORE THE POT NUMBER IN INTEGER FORMAT */ /* WHICH PROPFIND IS CLIENT SENDING??? */ if (strcasecmp(requestDetail, "SERVER") == 0) { /* PROPFIND ON SERVER */ if (sprintf(theMessage, "%s %sServer Properties:\nCoffeepot server version: %s\nNumber of coffeepots: %d\r\n", VERSION, OK, VERSION, POTS) < 0) { /* ERROR BUILDING RESPONSE! */ printf("ERROR! Could not build a response for client (%s)\n", clientIP); strcpy(theMessage, "NULL"); return theMessage; } else { printf("(%s) SENT A PROPFIND REQUEST (SERVER)\n", clientIP); return theMessage; } } else if (strncasecmp(requestDetail, "POT-", 4) == 0) { /* PROPFIND REQUEST FOR POT-X */ /* FIND OUT THE COFFEEPOT NUMBER CLIENT WISHES TO PROPFIND */ if (requestDetail[5]) { /* POT NUMBER IS DOUBLE FIGURES (ABOVE 9) */ char potNoS[2]; potNoS[0] = requestDetail[4]; potNoS[1] = requestDetail[5]; potNo = atoi(potNoS); /* CONVERT FROM ASCII TO INT */ } else if ((requestDetail[5]) && (requestDetail[6])) { /* POT NUMBER IS TRIPPLE FIGURES OR MORE - DEFINATLEY NOT SUPPORTED BY THIS SERVER */ potNo = -1; /* SET TO INVALID POT NUMBER */ } else { /* POT NUMBER IS SINGLE FIGURES */ potNo = requestDetail[4]; potNo -= '0'; /* CONVER FROM CHAR TO INT */ } /* IS THE POT NUMBER VALID? */ if ((potNo <= 0) || (potNo > POTS)){ /* BUILD THE PROPFIND RESPONSE MESSAGE */ if (sprintf(theMessage, "%s %sERROR! No such coffeepot (pot-%d) exists on this server!\r\n", VERSION, SERVICE_UNAVAILABLE, potNo) < 0) { /* AN ERROR BUILDING RESPONSE */ printf("ERROR! Could not build response for client (%s)\n", clientIP); strcpy(theMessage, "NULL"); return theMessage; } else { /* AN INVALID PROPFIND REQUEST WAS SENT! */ printf("(%s) JUST SENT AN INVALID PROPFIND REQUEST (POT-%d)\n", clientIP, potNo); return theMessage; } } else { bzero(theMessage, MAXBUFF); /* RESPOND TO CLIENT WITH THE PROPERTIES OF THE REQUESTED POT! */ if (sprintf(theMessage, "%s %sProperties for POT-%d\nCan store %d cup(s) of coffee\nContains %d cups of coffee\r\n", VERSION, OK, potNo, FULL, theMachine.coffeepots[potNo - 1]) < 0) { /* AN ERROR BUILDING RESPONSE */ printf("ERROR! Could not build response for client (%s)\n", clientIP); strcpy(theMessage, "NULL"); return theMessage; } else { return theMessage; } } /* BAD PROPFIND REQUEST */ else { /* RESPOND TO CLIENT */ if (sprintf(theMessage, "%s %s ERROR! Un-Recognised PROPFIND request!\r\n", VERSION, BAD_REQUEST) < 0) { /* AN ERROR BUILDING RESPONSE!!! */ printf("ERROR! Could not build response for client (%s)\n", clientIP); strcpy(theMessage, "NULL"); return theMessage; } else { return theMessage; } } } } /* propfindRequest() */
here is the output from the compiler as it stands....
Many thanks, Matt.Code:cd ~/socket/ gcc -o server server.c server.c: In function `propfindRequest': server.c:218: warning: return from incompatible pointer type server.c:218: warning: function returns address of local variable server.c:222: warning: return from incompatible pointer type server.c:222: warning: function returns address of local variable server.c:248: warning: return from incompatible pointer type server.c:248: warning: function returns address of local variable server.c:253: warning: return from incompatible pointer type server.c:253: warning: function returns address of local variable server.c:264: warning: return from incompatible pointer type server.c:264: warning: function returns address of local variable server.c:267: warning: return from incompatible pointer type server.c:267: warning: function returns address of local variable server.c:271: error: syntax error before "else" server.c:277: warning: return from incompatible pointer type server.c:277: warning: function returns address of local variable server.c:280: warning: return from incompatible pointer type server.c:280: warning: function returns address of local variable server.c: At top level: server.c:283: error: syntax error before '}' token server.c: In function `main': server.c:442: warning: passing arg 2 of `propfindRequest' makes pointer from integer without a cast server.c:442: error: too many arguments to function `propfindRequest' Compilation exited abnormally with code 1 at Thu Mar 30 12:55:39



LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.