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");
     listen(sockfd,5);
     clilen = sizeof(cli_addr);
     newsockfd = accept(sockfd, 
                 (struct sockaddr *) &cli_addr, 
                 &clilen);
     if (newsockfd < 0) 
          error("ERROR on accept");
     bzero(buffer,256);
     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");

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

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

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

     return 0; 
}

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

forth..

Niek

thanx...goin to try it out..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.