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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:47:57+00:00 2026-06-05T22:47:57+00:00

I was trying to write out some of the implementations of the string functions

  • 0

I was trying to write out some of the implementations of the string functions available in C. My code is:

#include <stdio.h>
#include <stdlib.h>   

char *mystrcpy(char *s1, char *s2)
{
    while(*s1++ = *s2++);
    return s1;
}

int mystrlen(char *s)
{
    int len = 0;
    while(*s != '\0')
    {
        len++;
    }
    return len;
}

int main(void)
{
    char arr = "Hi";
    char arr1[10];
    char arr2[] = "Hello";
    int length;

    mystrcpy(arr1, arr2);
    printf("%s", arr1);

    length = mystrlen(arr);
    printf("%d", length);

    return 0;
}

mystrcpy works fine, but the other method mystrlen does no execute. What could be the error? The following is the program termination note:

Process terminated with status -1073741510 (0 minutes, 4 seconds)

Also, there are few warnings related to casts. Is there any place in the code where I should be using any cast?

  • 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-05T22:47:59+00:00Added an answer on June 5, 2026 at 10:47 pm

    First, your mystrlen has an infinite loop.

    Fixed code:

    int mystrlen(const char *s)
    {
        int len = 0;
        while (*s++ /* increment to next character every loop */ != '\0')
        {
            len++;
        }
        return len;
    }
    

    Also added const since you never change the data referred to by *s

    Second, the assignment: char arr="Hi"; is not valid.

    You are attempting to assign a char[] array to a char variable. The correct form would be one of the following:

    char arr[]="Hi"; // array syntax
    char *arr="Hi";  // pointer syntax
    

    Given your invalid arr assignment, your runtime error is most likely caused by mystrlen attempting to incorrectly deference arr.

    What compiler are you using? Most conforming compilers should have caught the second issue. If using GCC, add the -Wall flag to your makefile.

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

Sidebar

Related Questions

I'm am trying to write vba code to fill out web-forms and click buttons
So i'm trying to write out an object to a ByteArray, but for some
I'm trying to increment through JQuery loop to fill out some HTML code with
Okay so i am trying to write a simple awk to clear out some
I am trying to write out some data to a file. However, every time
I'm trying to write out a bit of code for the gradient descent algorithm
Trying to write out syslog entries containing strings but they don't register. // person.name
Ultimately I'm trying to write out a range into a text file. When I
I am trying to write out a regex to get each insert line from
I'm trying to write Unicode characters (♠) using System.out , and a question mark

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.