am trying to write a simple server program that prompts the user for an ISBN number or an author. it should check if the number is a valid number i.e if the number is 4 digits...it should also check if the user has entered a number or characters..it should then read the ISBN number(if it is wat the user has entered) and display the book details from a text file...the book details should be stored by the user....here is what i have since the code is very long am only going to put from binding.....thanx and i can post the whole code if it is necessary..

if (bind(sockfd, (struct sockaddr *) &serv_addr,
              sizeof(serv_addr)) < 0) 
              error("ERROR on binding");
     clilen = sizeof(cli_addr);
     newsockfd = accept(sockfd, 
                 (struct sockaddr *) &cli_addr, 
     if (newsockfd < 0) 
          error("ERROR on accept");
     n = read(newsockfd,buffer,255);
     if (n < 0) error("ERROR reading from socket");
     if (buffer='ISBN')
       int ISBN,fISBN[500];
       int i=0,j=0;
       char buffer[256];
       int n, newsockfd;
       FILE *fp = fopen(FILE_NAME, "r");

           fscanf(fp,"%d", ISBN[i]); //loop thru the numbers into the array
       if (i<4) error("ERROR:Incorrect ISBN number");

      n = write(newsockfd,fISBN,18);
      if (n<0) error("ERROR writing to socket");

     printf("ERROR: Request does not exist\n");
     printf("%s\n" , &buffer);

     return 0; 
8 Years
Discussion Span
Last Post by joshmo

First thing I notice is this line :

if (buffer='ISBN')

This line means: if (assign 'ISBN' to buffer) ==succes
But that is probably not what you meant. (even if it was, it would still fail) I'm guesssing that you want to check if buffer hold "ISBN" as value?
If that's the case, you should look at strcmp() to compare the buffer with the string "ISBN"

Second thing is that char buffer[] is used, while it is not even defined yet.
This problem should have triggered a compiler error? (same problem with newsockfd and 'n')

Third: fscanf(fp,"%d", ISBN[i]); ISBN is NOT an array



This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.