I have been working on this for some time and need some help. I have posted to another forum with no results. I figured i would try here and see if i can get some real help. I am trying to populate an array with the contents of a file using fgets. I have a text file with 4 lines to test out my program and my program only prints the 4th line and then a new line and exits. I wrote a mini chat and am going turn it into an FTP server. So here is my data handler section
for( ; ; )
{
int size, count = 0;
FILE *fd;
fd = fopen(argv[3], "r");
fseek(fd, 0, SEEK_END);
size = ftell(fd);
rewind(fd);
if(fd == NULL)
{
printf("%s. FD(NULL)\n", strerror(errno));
exit(EXIT_FAILURE);
}
else if(fd)
{
while(count < size)
{
count++;
while((fgets(buffer, sizeof(buffer), fd)) != NULL)
{
//fgets(buffer, sizeof(buffer), fd);
}
}
writefd = write(sockfd, buffer, strlen(buffer));
if(writefd <= 0)
{
printf("%s. WRITE(-1).\n", strerror(errno));
exit(EXIT_FAILURE);
}
}
if((readfd = read(sockfd, buffer, sizeof(buffer))) < 0);
{
fprintf(stderr, "Error reading message from %s\n", inet_ntoa(cli_addr.sin_addr));
printf("%s. READ(c)\n", strerror(errno));
exit(0);
}
//Test to see if the buffer is blank. Uncomment to test.
if(readfd == 0)
{
printf("Null buffer. READ(0)\n");
}
else
{
fprintf(stdout, "%s", buffer);
}
}
i would really appreciate any help or guidance. Thanks