-1

I am trying to build a logic in c to come out from an infinite loop when input is taken from the user otherwise continue looping. But the loop get halted and my program starts waiting for the input. So, friends can you help me and suggest me some idea to implement the logic. The os is linux code starts waiting at if conditon.

while(1) {
     recv(sock,&data,sizeof(data),0);
     printf("\nthe recieved data from the server is: %d\n",data);
     fflush(stdout);

     if (scanf("%c",&control)==1 && control=='b')
     {
         send(sock,&control,1,0);
         break;
     }
     else continue;
}
glglgl
  • 89,107
  • 13
  • 149
  • 217
tod
  • 81
  • 1
  • 6

1 Answers1

0

You're probably using a blocking function to obtain user input, so the program will halt on that function until the user inputs something.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625