I want to read the file and match 2 words first i connect with a socket get the input write it to a file then i wanna read that file and get the match of 2 words and do something afterword but seems like it doesn't work So here is the code
#include<stdio.h>
#include<string.h> //strlen
#include<sys/socket.h>
#include<arpa/inet.h> //inet_addr
int main(int argc , char *argv[])
{
int socket_desc;
struct sockaddr_in server;
char *message, server_reply [2000];
FILE *f;
//Create socket
socket_desc = socket(AF_INET , SOCK_STREAM , 0);
if (socket_desc == -1)
{
printf("Could not create socket");
}
server.sin_addr.s_addr = inet_addr("86.127.118.157");
server.sin_family = AF_INET;
server.sin_port = htons( 80 );
//Connect to remote server
if (connect(socket_desc , (struct sockaddr *)&server , sizeof(server)) < 0)
{
puts("connect error");
return 1;
}
puts("Connected\n");
//Send some data
message = "GET / HTTP/1.1\r\n\r\n";
if( send(socket_desc , message , strlen(message) , 0) < 0)
{
puts("Send failed");
return 1;
}
puts("Data Send\n");
//Receive a reply from the server
if( recv(socket_desc, server_reply , 2000 , 0) < 0)
{
puts("recv failed");
}
puts("Reply received\n");
puts(server_reply);
// Open and write the file
f = fopen("date.txt", "w");
fprintf(f, server_reply);
// read and match the words
while (fgets (server_reply, 2500, f)) {
if( strcmp(server_reply, "258"))
{
fputs(server_reply, f);
}else{
puts("I could not loccate the bug");
}
// file close
fclose(f);
return 0;
}
}