i am receiving segmentation fault here is the code
client.c
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include <arpa/inet.h>
#define PORT 10001
main
int main(int argc ,char *argv[])
{
struct sockaddr_in address;
int sock = 0, valread,i=1;
struct sockaddr_in serv_addr;
char *hello = "Hello from client";
char buffer[1024] = {0};
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
printf("\n Socket creation error \n");
return -1;
}
memset(&serv_addr,'0',sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(PORT);
if(inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr)<=0)
{
printf("\nInvalid address/ Address not supported \n");
return -1;
}
if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) == -1)
{
printf("\nConnection Failed \n");
return -1;
}
send(sock , hello , strlen(hello) , 0 );
//printf("Hello message sent\n");
valread = read( sock , buffer, 1024);
printf("%d\t %s \n",i,buffer);
**here i am getting segmentation fault**
while(1)
{
valread = read( sock , buffer, 1024);
printf("%d\t %s \n",i,buffer);
scanf("%s",hello);
send(sock , hello , strlen(hello) , 0 );
i++;
if(strcmp(buffer,"bye")==1)
{
break;
}
}
return 0;
}