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 7652685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:50:07+00:00 2026-05-31T11:50:07+00:00

C does not make this easy. I looked all over, found nothing. I need

  • 0

C does not make this easy. I looked all over, found nothing.

I need to search a C string for a substring starting with “Sample: “, then create a new c string that consists of all the characters after that until the first newline.

In C++ I could do this in a heartbeat. Can a more experienced C programmer show me the way?

I’m sure i could do this by writing it out by hand, but surely there are SOME built-in functions that help?

  • 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-31T11:50:08+00:00Added an answer on May 31, 2026 at 11:50 am

    strstr() and strndup() are your friends, just remember to free the output when you are done:

    const char *input = "Hello Sample: This is a test\nTest";
    
    const char *start = strstr(input, "Sample: ");
    
    if (!start)
    {
        // report error here
    }
    
    const char *end = strstr(start, "\n");
    if (!end)
    {
        // you have two options here. 
        // #1: use pure strdup on start and you have your output
        // #2: make this an error, and report it to the user.
    }
    
    
    int length = end - start;
    
    char *output = strndup(start, length);
    
    printf("%s", output); // Prints "Sample: This is a test"
    
    free(output);
    

    It isn’t too hard if you know the right API calls.

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

Sidebar

Related Questions

In Oracle, this returns 03/01/2010. That does not make sense to me. Anybody know
Does this make sense? MyValue can be true or false Should it not be
As I just found out import package does not make the package's modules available
While it does not make much sense in the general case as it should
I'm trying to build expandableList with SimpleCursorTreeAdapter but my list does not make groups,
Ok, question does not really make sense. Here is the situation. I have legacy
I want to make Raty read-only in the click event, but it does not
I have the following code; I want to make sure that submit does not
does anybody know how to make EJBTimers persistent not in filesystem, but in selected
Does the length of the CommandText of an SqlCommand make a difference? I'm not

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.