Cześć,
mam taki kod jak poniżej. Dołączałem do niego pliki #include ale robiłem to nadmiarowo podczas pisania programu.
Czy można jakoś bez analizy konkretnych funkcji użytych w programie usunąć nie wykorzystywane pliki #include???
#include <netdb.h>
#include <string.h>
#include <arpa/inet.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/un.h>
#include <errno.h>
#include <stdlib.h>
#include <signal.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include "baza.h"
#define SIZE sizeof(struct sockaddr_in)
int main()
{
int sockfd;
char c, rc;
struct sockaddr_in server = {AF_INET, 7000};
/* przeksztalc i zapamietaj adres ip serwera */
server.sin_addr.s_addr = inet_addr("127.0.0.1");
/* ustaw punkt koncowy transportu: */
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
perror("socket call failed");
exit(1);
}
/* polacz gniazdo z adresem serwera: */
if (connect(sockfd, (struct sockaddr *)&server, SIZE) == -1)
{
perror("connect call failed");
exit(1);
}
/* wysylaj i odbieraj informacje od serwera: */
while(1)
{
rc='b';
printf("Wybierz opcje:\nq - wyjscie\na - dodaj\nd - usun\ns - wyszukaj\n");
scanf(" %c",&c);
if (c == 'q')
{ send(sockfd, &c, 1, 0);
printf("Program konczy prace...\n");
exit(0);
}
produkt * temp;
int tempNumer;
switch(c)
{
case 'a':
temp = malloc(sizeof(produkt));
printf("Podaj numer produktu[spacja]nazwa do 20 znakow[spacja]cena\n");
scanf(" %d %s %f",&temp->numer, &temp->nazwa, &temp->cena);
send(sockfd, &c, 1, 0);
send(sockfd, temp, sizeof(produkt), 0);
if(recv(sockfd, &rc, 1, 0) > 0)
{
if(rc == 'A')
printf("Dodano pomyslnie!");
else if(rc =='b')
printf("Blad dodawania!");
}
else
{
printf("Server has died.\n");
close(sockfd);
exit(0);
}
free(temp);
break;
case 'd':
printf("Podaj numer produktu do usuniecia\n");
scanf(" %d",&tempNumer);
send(sockfd, &c, 1,0);
send(sockfd, &tempNumer, sizeof(int), 0);
if(recv(sockfd, &rc, 1, 0) > 0)
{
if(rc == 'D')
printf("Usunieto pomyslnie!");
else if(rc =='b')
printf("Blad usuwania!");
}
else
{
printf("Server has died.\n");
close(sockfd);
exit(0);
}
break;
case 's':
printf("Podaj nr do wyszukania:\n");
scanf(" %d", &tempNumer);
send(sockfd,&c, 1, 0);
send(sockfd,&tempNumer, sizeof(int), 0);
produkt * temp = malloc(sizeof(produkt));
if(recv(sockfd, &rc, 1, 0) > 0)
{
if(rc == 'S')
{
if(recv(sockfd, temp, sizeof(produkt), 0)>0)
{
printf("Znaleziono: %d %s %.2f", temp->numer, temp->nazwa, temp->cena);
free(temp);
}
else
{
printf("Blad odpowiedzi na zapytanie!");
}
}
else if(rc =='b')
printf("Blad szukania!");
}
else
{
printf("Server has died.\n");
close(sockfd);
exit(0);
}
break;
}
}
}
cpp_int
boost::asio
i inne. Boost zawsze był wydajniejszym rozwiązaniem.