Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8735425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:03:21+00:00 2026-06-13T10:03:21+00:00

I write a network.h and network.c file. When I compile it with gcc. It

  • 0

I write a network.h and network.c file. When I compile it with gcc. It show a strange
error.

gcc -o network.o -c network.h

network.c:14: error: expected ‘;’, ‘,’ or ‘)’ before ‘{’ token

The code try to send message through socket.

This is the header file.

network.h

#ifndef _NETWORK_H_
#define _NETWORK_H_

int open_tcp(char* host, int port);
int nsend(int sock_fd, char* buffer, int num);
int nrecv(int sock_fd, char* buffer, int num;
int recv_line();
int close(int socket_fd);

#endif

This is the part of implements.

network.c

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h> 
#include <stdlib.h>
#include "network.h"

#define BUFFER_SIZE 300000

int open_tcp(char* host, int port)
{
    int sockfd, n;
    struct sockaddr_in serv_addr;
    struct hostent *server;

    sockfd = -1;
    char buffer[BUFFER_SIZE];
    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd < 0) 
        error("ERROR opening socket");
    server = gethostbyname(host);
    if (server == NULL) {
        fprintf(stderr,"ERROR, no such host\n");
        exit(0);
    }
    bzero((char *) &serv_addr, sizeof(serv_addr));
    serv_addr.sin_family = AF_INET;
    bcopy((char *)server->h_addr, 
         (char *)&serv_addr.sin_addr.s_addr,
         server->h_length);
    serv_addr.sin_port = htons(port);
    if (connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0) 
        error("ERROR connecting");
    return sockfd;
}

Thank you for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:03:22+00:00Added an answer on June 13, 2026 at 10:03 am

    If you give a minute to read the error it says,

    network.c:14: error: expected ‘;’, ‘,’ or ‘)’ before ‘{’ token
    

    Now, if you know that #include just includes the file and put the content of the file into the current file, so you can just count the lines (in this case as the files are small), you’ll arrive at line 6 in network.h, which has the issue i.e. this line

    int nrecv(int sock_fd, char* buffer, int num;
    

    Hope this helps in your better understanding and help you resolves such error by finding the exact error location.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I try to write a file to a network drive, that is disconnected,
How to Write/Read a file to/from a network folder/share using python? The application will
hi the win mobile 6 code tries to write files on network shared folder,
I am trying to write a file to a network drive from my asp.Net
I'm writing an application that needs to send a file over the network. I've
I try to write an xml file from a datatable. for (int i =
I am using network stream to send a file name (example :text.txt) and then
I am trying to write a bat file for a network policy that will
i'm supposed to write code which when given a text file (source code) as
Newbie here, I'm trying to write to an auto-generated /etc/network/interfaces file of a newely

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.