Sponsored Content
Top Forums Programming How to allocate memory to a string in C? Post 302528390 by AAKhan on Tuesday 7th of June 2011 04:53:15 AM
Old 06-07-2011
hi
Here is the working code
/* This method takes String, Start Length and End Length as input parameters, sub string the string and returns it */

char* getsubstring(const char* urstr, size_t beginL, size_t len)
{
if (urstr == 0 || strlen(urstr) == 0 || strlen(urstr) < begin || strlen(urstr) < (beginL+len))
return 0;
return strndup(urstr + beginL, len);
}

Thanks
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Unix Help - allocate more memory to /tmp

Hi Guys I using Solaris 8 and I need to change the size of my /tmp file. Was wondering does anyone know how to do this. Thanks Carson (1 Reply)
Discussion started by: cmackin
1 Replies

2. Programming

how allocate virtual memory

Hi Folks can any body suggest how to allocate virtual memory any function for that (2 Replies)
Discussion started by: munnu
2 Replies

3. UNIX for Advanced & Expert Users

unable to allocate enough memory

On SunOS 5.8 I get an error when starting a large Java process with over 2Gb memory. Error occurred during initialization of VM Could not reserve enough space for object heap When stopping several other Java processes we can start this process. This seems to indicate that we don't have... (11 Replies)
Discussion started by: rein
11 Replies

4. UNIX for Advanced & Expert Users

How to allocate memory

Hi, I have 2 systems with same hardware and software. One system is giving me error "Error occurred during initialization of VM Could not reserve enough space for object " when I tried to increase JBoss App's heap size to 2GB while the other system is running fine without any issue. Is there... (5 Replies)
Discussion started by: ravi3553
5 Replies

5. UNIX for Advanced & Expert Users

Oracle how many memory allocate really

hi... i want to find oracle allocate how many memory really.. i execute this code to list memory on unix system : ps -eo pmem,args | sort -k 1 -r -n outputs ; %mem command 12.9|ora_smon_RTX 12.9|ora_s000_RTX 12.9|ora_reco_RTX 12.9|ora_qmnc_RTX... (2 Replies)
Discussion started by: utoptas
2 Replies

6. SuSE

shmget failed - cannot allocate memory

Hi, In my proj, one process was running for 2 days. after 2 days its throwing an error message "shmget failed cannot allocate memory". the same problem happened every time.i.e. i can reproduce the same issue if my process is running for every 2 days for a same operation.Within this 2 days there... (1 Reply)
Discussion started by: ManoharanMani
1 Replies

7. Linux

shmget failed - cannot allocate memory

Hi, In my proj, one process was running for 2 days. after 2 days its throwing an error message "shmget failed cannot allocate memory". the same problem happened every time.i.e. i can reproduce the same issue if my process is running for every 2 days for a same operation.Within this 2 days there... (1 Reply)
Discussion started by: ManoharanMani
1 Replies

8. Linux

shmget failed - cannot allocate memory

Hi, In my proj, one process was running for 2 days. after 2 days its throwing an error message "shmget failed cannot allocate memory". the same problem happened every time.i.e. i can reproduce the same issue if my process is running for every 2 days for a same operation.Within this 2 days there... (1 Reply)
Discussion started by: ManoharanMani
1 Replies

9. Solaris

unable to allocate enough memory

On SunOS 10 get an error when starting a large Java process with over 2Gb memory. Error occurred during initialization of VM Could not reserve enough space for object heap i have 32G memory !! , swap = 31G Please any advice !!! (3 Replies)
Discussion started by: moata_u
3 Replies

10. Programming

calloc fails: 'Cannot allocate memory'

Hi , experts. I work on Linux station (RedHat 5.7), regular user, but have root password. %> uname -a Linux ran1log06 2.6.18-238.1.1.el5 #1 SMP Tue Jan 4 13:32:19 EST 2011 x86_64 x86_64 x86_64 GNU/Linux %> cat /etc/issue Red Hat Enterprise Linux Client release 5.7 (Tikanga) Kernel \r on... (5 Replies)
Discussion started by: baruchgu
5 Replies
StringLabels(3) 						   OCaml library						   StringLabels(3)

NAME
StringLabels - String operations. Module Module StringLabels Documentation Module StringLabels : sig end String operations. val length : string -> int Return the length (number of characters) of the given string. val get : string -> int -> char String.get s n returns character number n in string s . The first character is character number 0. The last character is character number String.length s - 1 . You can also write s.[n] instead of String.get s n . Raise Invalid_argument index out of bounds if n is outside the range 0 to (String.length s - 1) . val set : string -> int -> char -> unit String.set s n c modifies string s in place, replacing the character number n by c . You can also write s.[n] <- c instead of String.set s n c . Raise Invalid_argument index out of bounds if n is outside the range 0 to (String.length s - 1) . val create : int -> string String.create n returns a fresh string of length n . The string initially contains arbitrary characters. Raise Invalid_argument if n < 0 or n > Sys.max_string_length . val make : int -> char -> string String.make n c returns a fresh string of length n , filled with the character c . Raise Invalid_argument if n < 0 or n > Sys.max_string_length . val copy : string -> string Return a copy of the given string. val sub : string -> pos:int -> len:int -> string String.sub s start len returns a fresh string of length len , containing the characters number start to start + len - 1 of string s . Raise Invalid_argument if start and len do not designate a valid substring of s ; that is, if start < 0 , or len < 0 , or start + len > StringLabels.length s . val fill : string -> pos:int -> len:int -> char -> unit String.fill s start len c modifies string s in place, replacing the characters number start to start + len - 1 by c . Raise Invalid_argu- ment if start and len do not designate a valid substring of s . val blit : src:string -> src_pos:int -> dst:string -> dst_pos:int -> len:int -> unit String.blit src srcoff dst dstoff len copies len characters from string src , starting at character number srcoff , to string dst , start- ing at character number dstoff . It works correctly even if src and dst are the same string, and the source and destination chunks overlap. Raise Invalid_argument if srcoff and len do not designate a valid substring of src , or if dstoff and len do not designate a valid sub- string of dst . val concat : sep:string -> string list -> string String.concat sep sl concatenates the list of strings sl , inserting the separator string sep between each. val iter : f:(char -> unit) -> string -> unit String.iter f s applies function f in turn to all the characters of s . It is equivalent to f s.[0]; f s.[1]; ...; f s.[String.length s - 1]; () . val iteri : f:(int -> char -> unit) -> string -> unit Same as String.iter , but the function is applied to the index of the element as first argument (counting from 0), and the character itself as second argument. Since 4.00.0 val map : f:(char -> char) -> string -> string String.map f s applies function f in turn to all the characters of s and stores the results in a new string that is returned. Since 4.00.0 val trim : string -> string Return a copy of the argument, without leading and trailing whitespace. The characters regarded as whitespace are: ' ' , '12' , ' ' , ' ' , and ' ' . If there is no whitespace character in the argument, return the original string itself, not a copy. Since 4.00.0 val escaped : string -> string Return a copy of the argument, with special characters represented by escape sequences, following the lexical conventions of OCaml. If there is no special character in the argument, return the original string itself, not a copy. val index : string -> char -> int String.index s c returns the position of the leftmost occurrence of character c in string s . Raise Not_found if c does not occur in s . val rindex : string -> char -> int String.rindex s c returns the position of the rightmost occurrence of character c in string s . Raise Not_found if c does not occur in s . val index_from : string -> int -> char -> int Same as StringLabels.index , but start searching at the character position given as second argument. String.index s c is equivalent to String.index_from s 0 c . val rindex_from : string -> int -> char -> int Same as StringLabels.rindex , but start searching at the character position given as second argument. String.rindex s c is equivalent to String.rindex_from s (String.length s - 1) c . val contains : string -> char -> bool String.contains s c tests if character c appears in the string s . val contains_from : string -> int -> char -> bool String.contains_from s start c tests if character c appears in the substring of s starting from start to the end of s . Raise Invalid_argument if start is not a valid index of s . val rcontains_from : string -> int -> char -> bool String.rcontains_from s stop c tests if character c appears in the substring of s starting from the beginning of s to index stop . Raise Invalid_argument if stop is not a valid index of s . val uppercase : string -> string Return a copy of the argument, with all lowercase letters translated to uppercase, including accented letters of the ISO Latin-1 (8859-1) character set. val lowercase : string -> string Return a copy of the argument, with all uppercase letters translated to lowercase, including accented letters of the ISO Latin-1 (8859-1) character set. val capitalize : string -> string Return a copy of the argument, with the first character set to uppercase. val uncapitalize : string -> string Return a copy of the argument, with the first character set to lowercase. type t = string An alias for the type of strings. val compare : t -> t -> int The comparison function for strings, with the same specification as Pervasives.compare . Along with the type t , this function compare allows the module String to be passed as argument to the functors Set.Make and Map.Make . OCamldoc 2014-06-09 StringLabels(3)
All times are GMT -4. The time now is 07:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy