title: why when I declare an int variable my aplication freezes? C program
body: <p>this is my code for the server so far:
  a function that finds if a word is in a file:</p>
  <pre><code>int Search_in_File_name(char *fname, char *str) {
      FILE *fp;
      int line_num = 1;
      int find_result = 0;
      char temp[512];
      if((fp = fopen(fname, &quot;r&quot;)) == NULL) {
          return(-1);
      }
  
  
      while(fgets(temp, 512, fp) != NULL) {
          if((strstr(temp, str)) != NULL) {
              //printf(&quot;\n[copil] logare reusita&quot;);
              find_result++;
          }
          line_num++;
      }
  
      if(find_result == 0) {
          //printf(&quot;\nnume incorect&quot;);
          fclose(fp);
          return(3);
      }
      
      //Close the file if still open.
      if(fp) {
          fclose(fp);
      }
      return(4);
  }
  </code></pre>
  <p>and main where i have to look see if a client logs in before doing something else. I used fork for every client that connects to the server. I want to create a file in my project directory for every client and i need the number of the client to do that( or the port specified by &quot;ntohs(newAddr.sin_port)&quot; but i can't obtain the number of the client because i can't declare any int variables.</p>
  <pre><code>int main(){
  
      int sockfd, ret;
      struct sockaddr_in serverAddr;
  
      int newSocket;
      struct sockaddr_in newAddr;
  
      socklen_t addr_size;
  
      char buffer[1024];
      pid_t childpid;
  
      sockfd = socket(AF_INET, SOCK_STREAM, 0);
      if(sockfd &lt; 0){
          printf(&quot;[-]Error in connection.\n&quot;);
          exit(1);
      }
      printf(&quot;[+]Server Socket is created.\n&quot;);
  
      memset(&amp;serverAddr, '\0', sizeof(serverAddr));
      serverAddr.sin_family = AF_INET;
      serverAddr.sin_port = htons(PORT);
      serverAddr.sin_addr.s_addr = inet_addr(&quot;127.0.0.1&quot;);
  
      ret = bind(sockfd, (struct sockaddr*)&amp;serverAddr, sizeof(serverAddr));  //asociaza adresa serverAddr(localhost) la socketul creat (sockfd)
      if(ret &lt; 0){
          printf(&quot;[-]Error in binding.\n&quot;);
          exit(1);
      }
      printf(&quot;[+]Bind to port %d\n&quot;, PORT);
  
      if(listen(sockfd, 10) == 0){ //marcheaza socketul (sockfd) ca fiind socketul care va accepta o conexiune viitoare si limita maxima de conexiuni in asteptare 
          printf(&quot;[+]Listening....\n&quot;);
      }else{
          printf(&quot;[-]Error in binding.\n&quot;);
      }
  
      while(1){
          newSocket = accept(sockfd, (struct sockaddr*)&amp;newAddr, &amp;addr_size); //ia prima conexiune din lista asociata lui sockfd prin listen si creaza un nou socket si returneaza un descriptor de fisier pentru acel nou socket
          if(newSocket &lt; 0){
              exit(1);
          }
          printf(&quot;Connection accepted from %s:%d\n&quot;, inet_ntoa(newAddr.sin_addr), ntohs(newAddr.sin_port));
          
          int i=0; 
          if((childpid = fork()) == 0){
              close(sockfd);
              int ok=0;
              char* nume_fisier;
              
              while(1){
                  
                  recv(newSocket, buffer, 1024, 0);
                  if(strcmp(buffer, &quot;:exit&quot;) == 0){
                      printf(&quot;Disconnected from %s:%d\n&quot;, inet_ntoa(newAddr.sin_addr), ntohs(newAddr.sin_port));
                      break;
  
                  }else if(strncmp(c1, buffer, strlen(c1))==0 &amp;&amp; ok ==0){
                      int lungCom, lungNume;
                      char name[lungNume];
                      lungCom=strlen(buffer); //lungimea comenzii
                      lungNume=lungCom-strlen(c1); //lungimea numelui
                      name[lungNume]='\0';
                      strncpy(name,&amp;buffer[lungCom-lungNume],lungNume);//pun numele din comanda in variabia name
                      printf(&quot;\n[copil] asta e numele: %s &quot;, name);
                      printf(&quot;\n[copil] %s&quot;, w1);
                      if(Search_in_File_name(&quot;nume.txt&quot;, name)==4){// daca am gasit numele in lista
                          i=i+1;
                          printf(&quot;----%d----&quot;,i);
                          send(newSocket, v1, strlen(v1), 0);
                          bzero(buffer, sizeof(buffer));      
                          ok=1;
                          printf(&quot;\n[copil] am trimis mesajul: %s \n&quot;, v1); 
                      }else{ // daca nu am gasit numele in lista
                          send(newSocket, v2, strlen(v2), 0);
                          printf(&quot;\n[copil] am trimis mesajul: %s \n&quot;, v2); 
                          bzero(buffer, sizeof(buffer));      
                      }
                      
                      
                  }else if(strcmp(buffer, &quot;logout&quot;)==0 &amp;&amp; ok == 1){
                      printf(&quot;incercare delogare de la %s:%d\n&quot;, inet_ntoa(newAddr.sin_addr), ntohs(newAddr.sin_port));
                      printf(&quot;delogat de la  %s:%d\n&quot;, inet_ntoa(newAddr.sin_addr), ntohs(newAddr.sin_port));
                      ok=0;
                      printf(&quot;Client: %s\n&quot;, buffer);
                      send(newSocket, d1, strlen(d1), 0);
                      bzero(buffer, sizeof(buffer));
                  
                  }else if(strcmp(buffer, &quot;logout&quot;)==0 &amp;&amp; ok == 0){
                      printf(&quot;incercare delogare de la %s:%d\n&quot;, inet_ntoa(newAddr.sin_addr), ntohs(newAddr.sin_port));
                      printf(&quot;Client: %s\n&quot;, buffer);
                      send(newSocket, d2, strlen(d2), 0);
                      bzero(buffer, sizeof(buffer));
                      
                  }else if(strcmp(buffer, &quot;cos&quot;)==0 &amp;&amp; ok == 1){
                      printf(&quot;incercare creare cos de la %s:%d\n&quot;, inet_ntoa(newAddr.sin_addr), ntohs(newAddr.sin_port));
                      printf(&quot;Client: %s\n&quot;, buffer);
                      printf(&quot;----%d---:&quot;, ntohs(newAddr.sin_port));
                      //nume_fisier=creare_cos_client(nume_client);
                      //printf(&quot;---nume_fisier: %s&quot;, nume_fisier);
                      send(newSocket, cos1, strlen(cos1), 0);
                      bzero(buffer, sizeof(buffer));
                      
                          
                  }else{
                      printf(&quot;Client: %s\n&quot;, buffer);
                      send(newSocket, buffer, strlen(buffer), 0);
                      bzero(buffer, sizeof(buffer));
                  }
              }
          }
  
      }
  
      close(newSocket);
  
  
      return 0;
  }
  </code></pre>
  <p>If i delete that &quot;int i=0; &quot; before the fork my program works fine but as soon as i add it back(anywhere) the client can't take any input and the server doesn't check if the name is in the file or not. <a href="https://i.stack.imgur.com/o8ehK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/o8ehK.png" alt="this is how it freezes" /></a></p>