Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat kind of errors affect previous statements in C?
    primarykey
    data
    text
    <p>Sorry for a very generic sounding question.</p> <p>let's say</p> <pre><code>#include &lt;sys/socket.h&gt; #include &lt;sys/types.h&gt; #include &lt;netinet/in.h&gt; #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #include &lt;unistd.h&gt; #define SERVER_ADDRESS "123.456.789.012" #define CLIENT_ADDRESS "123.456.789.013" #define SERVER_TCP_PORT "1234" #define CLIENT_TCP_PORT "1235" int main() { printf("o halo thar"); int sockfd, new_sockfd, msg_len; void * got_msg = "got ur msg!"; void * message; struct sockaddr_in server_address, client_address; if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) &lt; 0 ) exit(1); printf("socket is opened"); bzero((char * ) &amp;server_address, sizeof(server_address)); server_address.sin_family = AF_INET; server_address.sin_addr.s_addr = htonl(SERVER_ADDRESS); server_address.sin_port = htons(SERVER_TCP_PORT); if (bind(sockfd, (struct sockaddr *) &amp;server_address, sizeof(server_address)) &lt; 0) exit(1); printf("socket is bound"); listen(sockfd,11); printf("listening"); if (accept(sockfd, (struct sockaddr *) &amp;client_address, sizeof(client_address)) &lt; 0) // THE BAD LINE exit(1); printf("accepted"); int i; for( i = 0; i &lt; 11; i++) { msg_len = recv(sockfd, (void *) message, 10000, 0); if (msg_len &lt; 1) exit(1); printf("receiving msg"); if (send(sockfd, (void *) got_msg, 10000, 0) &lt; 0); exit(1); printf("sending msg"); } close(sockfd); } </code></pre> <p>it should print <code>abc</code> if everything runs correctly. of course, my code doesn't. but i have localized the problem to this certain line of code which i'm calling <code>somecode()</code>. when i comment out <code>somecode()</code>, the program prints out <code>ab</code> (not <code>c</code>). however when not commented out, it prints nothing. so what kind of problem am i running into that affects previous statements? sorry for the vagueness. i'm just wondering how seeing <code>somecode()</code> is compiled fine, but when running, it influences executions of code that should be done before it reaches <code>somecode()</code>? Thanks guys.</p> <p>EDIT:somecode() being</p> <pre><code> if (accept(sockfd, (struct sockaddr *) &amp;client_address, sizeof(client_address)) &lt; 0) exit(1); </code></pre> <p>EDIT2: sorry for being too vague. i even forgot to describe what happens to the program. it doesn't print anything out and i have to ctrl+c in order to get out of it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload