Mistři v programování na #hovnokod

Ten blb čeká že po odpojení klienta se znovu spustí naslouchání -_-

/*
    C socket server example
*/
 
#include<stdio.h>
#include<string.h>    //strlen
#include<sys/socket.h>
#include<arpa/inet.h> //inet_addr
#include<unistd.h>    //write
#include<fcntl.h>
#include<sys/ioctl.h>
#include<netinet/in.h>

#include <wiringPi.h>
#include <wiringSerial.h>

 
int main(int argc , char *argv[])
{
    int socket_desc , client_sock , c , read_size;
    struct sockaddr_in server , client;
    char client_message[200];

    //Create socket
    socket_desc = socket(AF_INET , SOCK_STREAM, 0);
    if (socket_desc == -1)
    {
        printf("Could not create socket");
    }
    puts("Socket created");
     
    //Prepare the sockaddr_in structure
    server.sin_family = AF_INET;
    server.sin_addr.s_addr = INADDR_ANY;
    server.sin_port = htons( 8888 );
   
    //Bind
    if( bind(socket_desc,(struct sockaddr *)&server , sizeof(server)) < 0)
    {
        //print the error message
        perror("bind failed. Error");
        return 1;
    }
    puts("bind done");
     
    //Listen
    listen(socket_desc , 3);
     
    //Accept and incoming connection
    puts("Waiting for incoming connections...");
    c = sizeof(struct sockaddr_in);
  
    //accept connection from an incoming client
    client_sock = accept(socket_desc, (struct sockaddr *)&client, (socklen_t*)&c);
    if (client_sock < 0)
    {
        perror("accept failed");
        return 1;
    }
    puts("Connection accepted"); 
 
    //Receive a message from client
    while( (read_size = recv(client_sock , client_message , sizeof(client_message) , 0)) > 0 )
    {
	//Non-blocking Socket	
	ioctl(socket_desc, FIONBIO, (char *)&c); 

	//Terminal print control
        puts(client_message);

        //Send the message back to client
        write(client_sock , client_message , strlen(client_message));

	//SERIAL Connect
	int serial = serialOpen ("/dev/ttyS0", 9600);

	//SERIAL Send
	serialPrintf (serial, client_message) ;

	//Clear Buffer - client_message
        memset(client_message, 0, sizeof client_message);
    }
     
    if(read_size == 0)
    {
        puts("Client disconnected");
        fflush(stdout);
    }
    else if(read_size == -1)
    {
        perror("recv failed");
    }
     
    return 0;
}

Anonymous,

IFDEF pro každý bug

void wifi_start()
{
    #if WOP_A4_WIFI_API_SERVICE
#ifdef JIRA_WIFI0215_288
    uint32_t actual_flags = 0;
#endif //JIRA_WIFI0215_288
    OS_ERROR_CODE_T error;
#ifdef JIRA_WIFI0215_225
#if 0	//Disable the DCT
    /* Init DCT_1 */
    init_dct( );
    wiced_rtos_delay_milliseconds(1000);
#endif
#endif //JIRA_WIFI0215_225
    
#ifdef JIRA_WIFI0215_509	
     wwd_wifi_set_ioctl_value( WLC_SET_INTERFERENCE_MODE, 3, WWD_STA_INTERFACE );
#endif
#ifdef JIRA_WIFI0215_219	
    /* Register callbacks */
    wiced_network_register_link_callback( wifi_link_up, wifi_link_down, WICED_STA_INTERFACE );
#endif //JIRA_WIFI0215_219        

#ifdef JIRA_WIFI0215_288
    wiced_rtos_delay_milliseconds(1000);

    /* init flags for wifi async events */    
    wiced_rtos_init_event_flags( &g_wifiAsynEvent );
#endif     
    
#ifdef JIRA_WIFI0215_387
    wiced_rtos_init_timer  ( &update_radio_level, RADIO_LEVEL_UPDATE_PERIOD_MS, check_radio_level_event, NULL );

    // wiced_rtos_start_timer ( &update_radio_level );
#endif

#ifdef JIRA_WIFI0215_443
    host_rtos_init_semaphore( &scan_connect_semaphore );
    host_rtos_set_semaphore ( &scan_connect_semaphore, WICED_FALSE );
    
    wiced_rtos_init_timer ( &try_to_reconnect, RECONNECT_INTERVAL, reconnect_to_ap, NULL );
#endif //JIRA_WIFI0215_443

    wiced_set_ap_info_callback(wiced_vat_to_ap_info);
    /* finish wifi initialize */        
    g_isWifiInit = 1;

#ifdef JIRA_WIFI0215_288    
    while(1)
    {
        /* waiting for attach/detach event and send unsolict msg */
#ifdef JIRA_WIFI0215_443
        error = OS_EventWait(&g_wifiAsynEvent, &actual_flags, WIFI_ASYNC_EVENT_ATTACH | WIFI_ASYNC_EVENT_DETACH | WIFI_ASYNC_EVENT_RECONNECT, OS_FLAG_EVENT_ANY | OS_FLAG_CLEAR, TX_WAIT_FOREVER);
        assert(error == OS_ERR_OK);
#else      
        tx_event_flags_get( &g_wifiAsynEvent, (WIFI_ASYNC_EVENT_ATTACH | WIFI_ASYNC_EVENT_DETACH), TX_OR_CLEAR, &actual_flags, TX_WAIT_FOREVER );
#endif //JIRA_WIFI0215_443
#ifdef JIRA_WIFI0215_650
	if(g_flagSolicitedResponse == 0)
#endif
        send_Solicited_msg_to_wm( actual_flags );
#ifdef JIRA_WIFI0215_458
	send_keep_alive_data_package(actual_flags);
#endif

        actual_flags = 0;
    }
#endif //JIRA_WIFI0215_288
    #endif
}

Anonymous,

#include <iostream>
#include<stdlib.h>
#include<time.h>
#include<string>

using namespace std;
void menu(){
    cout<<"vyber si moznost"<<endl
       <<"1..Honzik"<<endl
      <<"2..Eda"<<endl
     <<"3..Georgiek"<<endl
    <<"4..Lenka"<<endl;
}

int main(int argc, char *argv[])
{
    menu();
    string seznam[4];
    seznam[0]="Honzik";
    seznam[1]="Eda";
    seznam[2]="Georgiek";
    seznam[3]="Lenka";
    int i;
    cin>>i;
    while(i==1){
        cout<<seznam[0]<<endl;
        break;
    }
    while(i==2){
        cout<<seznam[1]<<endl;
        break;
    }
    while(i==3){
        cout<<seznam[2]<<endl;
        break;
    }
    while(i==4){
        cout<<seznam[3]<<endl;
        break;
    }
}

Anonymous,

Kvalitni podminka vzdy potesi

        if (((rsFile_[i].dir_ == ANY_DIR) || (rsFile_[i].dir_ == dir)) && (messageSize >= rsFile_[i].messageSizeLow_) &&
            (messageSize <= rsFile_[i].messageSizeHigh_) &&
            ((rsFile_[i].recType_ == ANY_RT) || (rType == rsFile_[i].recType_)) &&
            compare_domains(domain, rsFile_[i].domain_) &&
            ((rsFile_[i].loc_ == ANY_LOC) || (loc == rsFile_[i].loc_)) &&
            (((rsFile_[i].scRangeLow_ == 0) && (rsFile_[i].scRangeHigh_ == UINT64_MAX)) ||
             ((bType == 2) && (is_numeric(MSISDN, 1) && (numMSISDN >= rsFile_[i].scRangeLow_) &&
                               (numMSISDN <= rsFile_[i].scRangeHigh_)))) &&
            ((rsFile_[i].cType_ == ANY_TYPE) || (cType == rsFile_[i].cType_))) {

Anonymous,

zadani prvniho cisla do pole a dalsich cisel pres while ?

#include <stdio.h>
#include <stdlib.h> 

int main() 
{
   int cisla[50], i;
   
   printf("Program pro zjisteni nejdelsiho useku cisel\n");
   
   i = 1;
   printf("Zadej %d. cislo: \n", i);
   scanf("%d", &cisla[i]);
   
   while (cisla[i] != 0) {
   		i++;
   		printf("Zadej %d. cislo: \n", i);
   		scanf("%d", &cisla[i]);
   }
   
   system("pause");
}

Anonymous,