Hi there
Below is a small bit of test code for a project im working on, eventually the programs going to be a simple file transfer system, reading a file and then sending it out of a socket, but for now I cant get any files to open. I've been pouring over it for hours and I can't find up whats going wrong, the files there and has data in, but all the read() will return is -1 with a stderr message of Bad File Descriptor, but i just cant figure it out.
Any help would be massively appreciated
Thank you
Dave
#include <stdio.h>
#include <sys/socket.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#define RCVBUFSIZE 2048
int main(int argc, char** argv)
{
FILE *iput_ptr;
char rcvBuffer[RCVBUFSIZE];
char fileName[8];
int nRead;
strcpy(fileName , "test.txt") ;
memset(rcvBuffe r,0,RCVBUFSIZE) ; // Zero out Receive Buffer
printf("%s", fileName);
iput_ptr = fopen(fileName, "r");
if(iput_ptr != NULL)
{
do
{
printf("pre read");
nRead = read(iput_ptr, rcvBuffer, RCVBUFSIZE-1);
printf("%i", nRead);
}
while (nRead > 0);
}
return 0;
}
Below is a small bit of test code for a project im working on, eventually the programs going to be a simple file transfer system, reading a file and then sending it out of a socket, but for now I cant get any files to open. I've been pouring over it for hours and I can't find up whats going wrong, the files there and has data in, but all the read() will return is -1 with a stderr message of Bad File Descriptor, but i just cant figure it out.
Any help would be massively appreciated
Thank you
Dave
#include <stdio.h>
#include <sys/socket.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#define RCVBUFSIZE 2048
int main(int argc, char** argv)
{
FILE *iput_ptr;
char rcvBuffer[RCVBUFSIZE];
char fileName[8];
int nRead;
strcpy(fileName , "test.txt") ;
memset(rcvBuffe r,0,RCVBUFSIZE) ; // Zero out Receive Buffer
printf("%s", fileName);
iput_ptr = fopen(fileName, "r");
if(iput_ptr != NULL)
{
do
{
printf("pre read");
nRead = read(iput_ptr, rcvBuffer, RCVBUFSIZE-1);
printf("%i", nRead);
}
while (nRead > 0);
}
return 0;
}
Comment