Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7553435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:03:18+00:00 2026-05-30T11:03:18+00:00

My code below takes a URL inputted by the user and prints out the

  • 0

My code below takes a URL inputted by the user and prints out the HTML coded content of the page. The first for() loop of the code is meant to strip out the code between the <…> in the HTML but i cant seem to get it to work, it is not printing anything.

Can anyone see if there is a problem with my code, it works fine but doesn’t remove or print anything out after the aforementioned for() loop.

#include <curl/curl.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
#include <string.h>

/*
 * 
 */

size_t write_data(void *ptr, size_t size, size_t nmeb, void *stream) {
    return fwrite(ptr, size, nmeb, stream);
}

/* function prototypes to define later */
char *do_web_request(char *url);
size_t static write_callback_func(void *buffer,
        size_t size,
        size_t nmemb,
        void *userp);

int main(int argc, char** argv) {

    char str[100];
    int len;
    printf("Enter the website URL:\n");
    scanf("%s", str);
    char *content = NULL;

    content = do_web_request(str);

    len = strlen(str);

    int i;
    int idx = 0;
    int opened = 0;

    printf("Original content::");
    printf("%s", content);

    printf("\nReplaced String ");

    for (i = 0; i < len; i++) {
        if (content[i] == '<') {
            opened = 1;
        } else if (content[i] == '>') {
            opened = 0;
        } else if (!opened) {
            content[idx++] = content[i];
        }
    }

    content[idx] = '\0';
    printf("%s\n", content);

    return (EXIT_SUCCESS);
}

/* the function to return the content for a url */
char *do_web_request(char *str) {
    /* keeps the handle to the curl object */
    CURL *curl_handle = NULL;
    /* to keep the response */
    char *response = NULL;

    /* initializing curl and setting the url */
    curl_handle = curl_easy_init();
    curl_easy_setopt(curl_handle, CURLOPT_URL, str);
    curl_easy_setopt(curl_handle, CURLOPT_HTTPGET, 1);

    /* follow locations specified by the response header */
    curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1);

    /* setting a callback function to return the data */
    curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_callback_func);

    /* passing the pointer to the response as the callback parameter */
    curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, &response);

    /* perform the request */
    curl_easy_perform(curl_handle);

    /* cleaning all curl stuff */
    curl_easy_cleanup(curl_handle);

    return response;
}

/* the function to invoke as the data recieved */
size_t static write_callback_func(void *buffer,
        size_t size,
        size_t nmemb,
        void *userp) {
    char **response_ptr = (char**) userp;

    /* assuming the response is a string */
    *response_ptr = strndup(buffer, (size_t) (size * nmemb));

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T11:03:20+00:00Added an answer on May 30, 2026 at 11:03 am

    I think this:

    len = strlen(str);
    

    should be:

    len = strlen(content);
    

    Otherwise, you won’t be correctly examining the returned HTML as the len would be the len of the URL entered by the user.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code below takes an array value, if it's key exist it should echo
the code below works fine but it takes an absolute age to run. How
Using the code below each image download) file_get_contents() ) takes on average 8-15 seconds.....
The page: /index.php?page=6&test=1&test2=2 The code below strip's page=6 off of this so I can
Below is my code (ASP.net web project), but when i debug this asp page
Hi wonder if anyone could help me. the first code below basically counted every
The code below is designed to take a string in and remove any of
In the code below, why it is that when I take the address of
I have a basic PHP question, take the code below for example, let's say
I'm using all of the below to take a field called 'code' from my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.