I'm a novice at c and not sure what to do.
com.c:176: warning: passing argument 1 of ‘sscanf’ makes pointer from integer without a cast
com.c:178: warning: passing argument 1 of ‘sscanf’ makes pointer from integer without a cast
com.c:182: warning: passing argument 2 of ‘send’ makes pointer from integer without a cast
They relate to the while loop situated at the bottom of this code:
- Code: Select all
#include <stdio.h> /* for printf() and fprintf() */
#include <sys/socket.h> /* for socket(), connect(), send(), and recv() */
#include <arpa/inet.h> /* for sockaddr_in and inet_addr() */
#include <stdlib.h> /* for atoi() and exit() */
#include <string.h> /* for memset() */
#include <unistd.h>
/* for close() */
#define BUFSIZE 4096 /* Size of receive buffer */
#define RCVBUFSIZE 32
void DieWithError(char *errorMessage); /* Error handling function */
void HandleTCPServer(int sock, char *argv[]); /* Server handling function */
int main(int argc, char *argv[])
{
int sock; /* Socket descriptor */
struct sockaddr_in echoServAddr; /* Echo server address */
unsigned short echoServPort; /* Echo server port */
char *servIP; /* Server IP address (dotted quad) */
char *echoString;
char echoBuffer[RCVBUFSIZE];
unsigned int echoStringLen;
int bytesRcvd, totalBytesRcvd;
unsigned int nrows=0; /* number of data rows in the file */
unsigned int comment=0; /* number of comment lines in file */
unsigned int i=0; /* counters */
const unsigned int linelen=700; /* length of buffer line */
FILE *fp; /* pointer to file to read data */
char userfile[40]; /* name of file to read */
char **buff; /* buffer line */
char templine[700]; /* temporary line for initial reading of the file */
unsigned int nrows1=0; /* number of data rows in the file */
unsigned int comment1=0; /* number of comment lines in file */
unsigned int j=0; /* counters */
const unsigned int linelen1=700; /* length of buffer line */
FILE *fp1; /* pointer to file to read data */
char passfile[40]; /* name of file to read */
char **buff1; /* buffer line */
char templine1[700]; /* temporary line for initial reading of the file */
char sendBuffer[BUFSIZE];
if ((argc < 3) || (argc > 4)) /* Test for correct number of arguments */
{
fprintf(stderr, "Usage: %s <Server IP> [<Port>]\n",argv[0]);
exit(1);
}
servIP = argv[1]; /* First arg: server IP address (dotted quad) */
echoString = argv[2];
if (argc == 4)
echoServPort = atoi(argv[3]); /* Use entered port */
else
echoServPort = 21; /* 21 for default port */
/* Create a reliable, stream socket using TCP */
if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
DieWithError("socket() failed");
/* Construct the server address structure */
memset(&echoServAddr, 0, sizeof(echoServAddr)); /* Zero out structure */
echoServAddr.sin_family = AF_INET; /* Internet address family */
echoServAddr.sin_addr.s_addr = inet_addr(servIP); /* Server IP address */
echoServAddr.sin_port = htons(echoServPort); /* Server port */
/* Establish the connection to the echo server */
if (connect(sock, (struct sockaddr *) &echoServAddr, sizeof(echoServAddr)) < 0)
DieWithError("connect() failed");
echoStringLen = strlen(echoString);
if (send(sock, echoString, echoStringLen, 0) != echoStringLen)
DieWithError("send() sent a differnet number of bytes then expected");
totalBytesRcvd = 0;
printf("Received: ");
while (totalBytesRcvd < echoStringLen)
{
if ((bytesRcvd = recv(sock, echoBuffer, RCVBUFSIZE -1, 0)) <=0 )
DieWithError("recv() failed or connection closed prematurely");
totalBytesRcvd += bytesRcvd;
echoBuffer[bytesRcvd] = '\0';
printf(echoBuffer);
}
printf("\n");
HandleTCPServer(sock, argv);
close(sock);
printf("Enter the name of the username file you want to read data from: ");
scanf("%s", userfile);
if (!(fp=fopen(userfile,"r"))) {
perror(userfile);
exit(1);
}
/* count the number of comment lines, and data lines */
while (fgets(templine,sizeof(templine),fp)!=NULL) {
if (templine[0]=='#') {
comment++;
} else {
nrows++;
}
}
printf("\nThere are %u comments and %u rows", comment, nrows);
/* allocate string array to write all the lines from the file */
buff=malloc((comment+nrows)*sizeof(*buff));
if (buff==NULL) {
printf("\nCould not allocate pointer array");
}
for (i=0; i<(comment+nrows); i++) {
buff[i]=malloc(linelen*sizeof(*buff[i]));
if (buff[i]==NULL) {
printf("\nCould not allocate array %u", i);
}
}
/* read all lines into buffer, and print to screen */
rewind(fp);
for (i=0; i<(comment+nrows); i++) {
fgets(buff[i],linelen*sizeof(buff[i]),fp);
printf("%s", buff[i]);
}
/* clean up memory */
fclose(fp);
for (i=0; i<(comment+nrows); i++) {
free(buff[i]);
}
free(buff);
/* open a file to read */
printf("Enter the name of the password file you want to read data from: ");
scanf("%s", passfile);
if (!(fp1=fopen(passfile,"r"))) {
perror(passfile);
exit(1);
}
/* count the number of comment lines, and data lines */
while (fgets(templine1,sizeof(templine1),fp1)!=NULL) {
if (templine1[0]=='#') {
comment1++;
} else {
nrows1++;
}
}
printf("\nThere are %u comments and %u rows", comment1, nrows1);
/* allocate string array to write all the lines from the file */
buff1=malloc((comment1+nrows1)*sizeof(*buff1));
if (buff1==NULL) {
printf("\nCould not allocate pointer array");
}
for (j=0; j<(comment1+nrows1); j++) {
buff1[j]=malloc(linelen1*sizeof(*buff1[j]));
if (buff1[j]==NULL) {
printf("\nCould not allocate array %u", j);
}
}
/* read all lines into buffer, and print to screen */
rewind(fp1);
for (j=0; j<(comment1+nrows1); j++) {
fgets(buff1[j],linelen1*sizeof(buff1[j]),fp1);
printf("%s", buff1[j]);
}
while(sscanf(BUFSIZE, "%s\n", userfile))
{
while(sscanf(BUFSIZE, "%s\n", passfile))
{
sprintf(sendBuffer, "USER %s\r\nPASS %s\r\n", userfile, passfile);
send(sock, strlen(sendBuffer), 0, 0);
memset(sendBuffer, 0, 256);
// Perhaps memset pass buffer here
}
// And user buffer here, but I'm not sure it's necessary.
}
/* clean up memory */
fclose(fp1);
for (j=0; j<(comment1+nrows1); j++) {
free(buff1[j]);
}
free(buff1);
return 0;
exit(0);
}


