This is An ama C programme Code that can find any word that you input.

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <curl/curl.h>

struct webpage_data

{

char *data;

size_t size;

};

size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata)

{

struct webpage_data *data = (struct webpage_data *)userdata;

size_t data_size = size * nmemb;

char *new_data = (char *)malloc(data->size + data_size + 1);

if (new_data == NULL)

{

fprintf(stderr, “Error: failed to allocate memory for webpage data.\n”);

return 0;

}

if (data->data != NULL)

{

memcpy(new_data, data->data, data->size);

free(data->data);

}

memcpy(&(new_data[data->size]), ptr, data_size);

data->size += data_size;

new_data[data->size] = ‘\0’;

data->data = new_data;

return data_size;

}

int main(void)

{

CURL *curl;

CURLcode res;

struct webpage_data data = {NULL, 0};

char threat[100];

char url[1000];

printf(“\033[4m\033[36m”);

printf(“Enter the threat to search for: “);

scanf(“%s”, threat);

printf(“Enter the URL to analyze: “);

scanf(“%s”, url);

curl_global_init(CURL_GLOBAL_DEFAULT);

curl = curl_easy_init();

if (curl)

{

curl_easy_setopt(curl, CURLOPT_URL, url);

curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);

curl_easy_setopt(curl, CURLOPT_WRITEDATA, &data);

res = curl_easy_perform(curl);

if (res != CURLE_OK)

{

fprintf(stderr, “Error downloading webpage: %s\n”, curl_easy_strerror(res));

}

else

{

char *found_line = strstr(data.data, threat);

if (found_line != NULL)

{

char *start_line = found_line;

while (*start_line != ‘\n’ && start_line != data.data)

{

start_line–;

}

if (*start_line == ‘\n’)

{

start_line++;

}

char *end_line = found_line;

while (*end_line != ‘\n’ && *end_line != ‘\0’)

{

end_line++;

}

*end_line = ‘\0’;

printf(“\nThe threat ‘%s’ was found on the webpage ‘%s’.\n”, threat, url);

printf(“The full line where the threat was found is:\n%s\n”, start_line);

}

else

{

printf(“\nThe threat ‘%s’ was not found on the webpage ‘%s’.\n”, threat, url);

}

}

curl_easy_cleanup(curl);

}

if (data.data != NULL)

{

free(data.data);

}

curl_global_cleanup();

return 0;

}

Leave a comment

Design a site like this with WordPress.com
Get started