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

  • Home
  • SEARCH
  • 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 7708581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:38:54+00:00 2026-06-01T00:38:54+00:00

i am writing a C program and one of the issues i have is

  • 0

i am writing a C program and one of the issues i have is to extract a word between two words as below.

ac_auto_lvalue[] =
    "ONLY / GROUP:  OTHERS EXAMPLE  /-----------------------------";

I need to extract the word between “Group:” and the “/”, the two words (Group:” & “/”) will always be there but the words in between can change and in some cases there might be nothing… ( in the above example output would be “OTHERS EXAMPLE”

can anyone help me with a C snippet for the above?

  • 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-06-01T00:38:56+00:00Added an answer on June 1, 2026 at 12:38 am

    Take a look at the strstr function. It lets you find a pointer to the first occurrence of a specific string (say, "Group:") inside another string. Once you have two pointers (to the beginning and to the end of your string) you can allocate enough memory using malloc (don’t forget the terminating zero '\0'), use memcpy to copy the characters, and finally zero-terminate your string.

    int main() {
        char ac_auto_lvalue[] = "ONLY / GROUP: OTHERS EXAMPLE /-----------------------------";
        // Adding 7 to compensate for the length of "GROUP: "
        const char *p1 = strstr(ac_auto_lvalue, "GROUP: ")+7;
        const char *p2 = strstr(p1, " /");
        size_t len = p2-p1;
        char *res = (char*)malloc(sizeof(char)*(len+1));
        strncpy(res, p1, len);
        res[len] = '\0';
        printf("'%s'\n", res);
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a simple program. There is only one class in it. There is
I am writing a GTKmm window program; the main window creates two buttons, one
I'm writing a program that for one part asks for the program to print
I am writing a GUI program. In one part of it I show an
I'm writing a custom text-to-speech program that uses SAPI 5, and one problem I'm
I am on MacOSX. I am writing a multi threaded program. One thread does
Im writing a program that should read input via stdin, so I have the
I'm about to start writing a program which will attempt to extract data from
I am having some issues with a program I am writing in C, and
I'm writing a small .NET program on Windows 7. One thing it needs to

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.