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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:46:34+00:00 2026-06-14T03:46:34+00:00

I have to try and use the GetSubstring function to print the result so

  • 0

I have to try and use the GetSubstring function to print the result so that

printf(GetSubstring("character", 4, 3, resultArray));

outputs act

Limitations: can’t call other functions or macros, can’t add any other variables, can’t set variable to 0. Can only change function GetSubstring.

Here is my current code.

#include <stdio.h>
#include <stdlib.h>
char *GetSubstring(const char source[], int start, int count, char result[]);

int main(void)
{
const char source[] = "one two three";
char result[] = "123456789012345678";

puts(GetSubstring("character", 4, 3, result));

return(EXIT_SUCCESS);
}


char *GetSubstring(const char source[], int start, int count, char result[])
{
    char *copy = result;
    for (; *source != '\0' || *source == source[start]; start--)
    {
        while (*source != '\0')
        {
        *result++ = *source++;
        }

    }

    *result = '\0';
    return (copy);                                      // outputs character
    // return (result);                                 // outputs 012345678
}

Thank you for your 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-06-14T03:46:35+00:00Added an answer on June 14, 2026 at 3:46 am

    This line is supposed to terminate the string:

    *result += '\0'
    

    But it doesn’t because you are adding zero to the existing value. Try setting it to zero instead:

    *result = '\0'
    

    More importantly, your loop is wack. This contains a whole lot of recipes for trouble:

    for (; *source != '\0' || *source == source[start]; start--)
    {
        while (*source != '\0')
        {
            *result++ = *source++;
        }
    }
    

    Why don’t you begin at start, and then increment…

    int i = 0;
    const char *str = &source[start];
    
    while( i < count && *str != '\0' ) {
        result[i++] = *str++;
    }
    result[i] = '\0';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok I have a base.html and I try to use that for my header
I have a loop that works but not when I try and use it
I have a program that creates semaphore. But when i try to use SETALL,
I have created windows service i have try to debug for that i use
I have started to try out to use the new Search API, the demo
I have a problem when try to use hashtable with large data. I have
I have this implementation with fusion table layers where I try to use the
so in my program I have parts where I use try catch blocks like
i am having this problem try to use the cocos2d CCScrollLayer I have added
Possible Duplicate: How to catch exceptions I have not really had to use try

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.