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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:51:00+00:00 2026-05-27T04:51:00+00:00

i just recently asked a question and got help but i have another problem

  • 0

i just recently asked a question and got help but i have another problem with my custom c string. everything compiles fine but when i try to get something it freezes, or it could be when i delete it. what am i doing wrong? heres my code:

main.c

#include <stdio.h>
#include "String.h"

int main(int argc, char *argv[]) {
  String *some_string = String_New("hello");
  printf("%s\n", String_CharPtr(some_string));
  String_Delete(some_string);
  return 0;
}

String.h

#ifndef _STRING_H
#define _STRING_H

typedef struct String String;

extern String *String_New(char */*basic_string*/);
extern void String_Delete(String */*string*/);
extern char *String_CharPtr(String */*string*/);
extern unsigned int String_GetLength(String */*string*/);
extern unsigned int String_GetSize(String */*string*/);

#endif

and finally:

String.c

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

#include "String.h"

struct String {
  char *basic_string;
  unsigned int length;
};

String *String_New(char *basic_string) {
  String *temp = NULL;
  temp->length = strlen(basic_string);
  temp->basic_string = (char *) malloc(temp->length + 1);
  strcpy(temp->basic_string, basic_string);
  return temp;
}

void String_Delete(String *string) {
  free(string->basic_string);
  string->basic_string = NULL;
}

char *String_CharPtr(String *string) {
  return string->basic_string;
}

unsigned int String_GetLength(String *string) {
  return string->length;
}

unsigned int String_GetSize(String *string) {
  return string->length + 1;
}
  • 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-27T04:51:01+00:00Added an answer on May 27, 2026 at 4:51 am
    String *temp = NULL;
    temp->length = strlen(basic_string);
    

    You haven’t allocated memory for temp.

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

Sidebar

Related Questions

I asked a question [ here ] recently and it's just not providing me
I have just started C very recently and I have been asked to answer
Recently I asked this question: Removing up to 4 spaces from a string and
Please, help me clear my mind on the following question. Recently I asked a
i recently asked this question and i got a lot of great answers breaking
I just recently asked this question: https://stackoverflow.com/questions/6359367/running-a-bash-program-every-day-at-the-same-time The solution of using crontab -e to
I recently asked this question: Compiler error referencing custom C# extension method Marc Gravell
I had recently asked a related question In C# how do I have a
I recently asked a question that got shot down for being too strongly worded.
I've just recently asked the folloiwng question with regard to jQuery chaning: Is there

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.