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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:11:59+00:00 2026-06-11T01:11:59+00:00

This is part of a lab assignment I have to implement the following function…

  • 0

This is part of a lab assignment

I have to implement the following function…

void replaceChar(char s[], char c,int len)

Description: Replace every character of s with c. len indicates the length of s.

I submit this to the autograder that my class uses and it tells me that “the length of the replaced string has different length.” I have tested this extensively and do not see any issues. Here is my complete function:

void replaceChar(char s[], char c, int len) {
    printf("\n");
    for (int i = 0; i < len; i++) {
        s[i] = c;
        printf("%c",s[i]);
    }
}

I appreciate any help you can give me!

Here are a few of my test cases:

char s1[5] = {'h','e','l','l','o'};

char s3[10] = {'h','e','l','l','o',' ','h','i','i','i'};
char rep1 = 'x';
replaceChar(s1,rep1,5);
replaceChar(s3,rep1,10);
  • 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-11T01:12:01+00:00Added an answer on June 11, 2026 at 1:12 am

    See my comment:

    have you tried explicitly marking the NUL terminator? s[len] = '\0';

    Though this corrects the issue, I’d still get in contact with your professors and ask them why this was necessary in the first place. The lab does not specify that the string s needs to be NUL-terminated.

    As an aside (mentioned originally in another of my comments), you should take advantage of using string literals when initializing s1 and s3, i.e.

    char s1[] = "hello";
    char s3[] = "hello hiii";
    

    This not only looks much cleaner (and avoids the need to explicitly mention the array length) but also guarantees the strings are NUL-terminated to begin with, too.

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

Sidebar

Related Questions

This part of my code works fine: #include <stdio.h> int main(){ //char somestring[3] =
This part of an app that I am working on, I have the following
I have this part of script from my GAE application which uses webapp2, which
I have this part of code that was compiling using ARMASM : /* Software
I have this part of code string query = SELECT ID, COL1 FROM TABLE1
Recently I have done this part of code. It does work, but select() works
I have this mysql query using PHP and first part is working fine, but
I've this part of code: public void onClickHandler(View a) { String pressed = null;
I have this part of a query : GROUP BY trackid ORDER BY MAX(history.date)
I have this part in asp.net MVC 3 view: <tr> <td>@Html.LabelFor(x => x.DateOfBirth, new

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.