Re: General method for dynamically allocating memory for a string



"smnoff" <343rhinosourueus@xxxxxxxxxxx> writes:

I have searched the internet for malloc and dynamic malloc; however, I still
don't know or readily see what is general way to allocate memory to char *
variable that I want to assign the substring that I found inside of a
string.

If you want to allocate memory for a string, pass the number of
non-null characters in it, plus one, to malloc, then copy the
string into it, being sure to null-terminate the result.

If you can be more specific about what you're trying to do,
perhaps we can help with some details.
--
"I hope, some day, to learn to read.
It seems to be even harder than writing."
--Richard Heathfield
.



Relevant Pages

  • Re: help getting substring
    ... I need a program to extract a substring from the following pattern ... char* deangle ... What does deangle do when passed a string of the form ... char *deangle(char *str) ...
    (comp.lang.c)
  • Re: String.substring, under the hood
    ... substring is clever. ... It does not make a deep copy of the substring the ... immutable String, i.e. points to the value char[] of the base string, ...
    (comp.lang.java.programmer)
  • Re: need some help
    ... mystrstr - find the first occurrence of substring in string ... char *mystrstr ... int next; ...
    (comp.lang.c)
  • strstr(char *str1, char *str2)
    ... I'm new to this C - never the less - I'm trying to search a string for the ... a substring, as I can see it with my own two eye when I print out the string ... char *resolveResponse{ ... char *endOfResponse; char *startOfFile; ...
    (comp.lang.c)
  • Re: Newbie. Microsoft Visual Express 2008. Problem with Assignment
    ... char *encrypt_string ... the encrypted data except for the terminal '\0'. ...
    (comp.lang.c)