What actually happens if I don't malloc space for the strings, (in the situation as mentioned in my previous post), and the strings that the array points to change all the time. What about the space the old strings occupy, will that automaticly be free space, or will it be occupied until the program terminates?
I really haven't got your question, but will try to answer just the same,
If you declare a character array for strings like char a[50], then you can have the string that occupies it change frequently over the course of your program, but as long as it does not go over 50*sizeo(char) bytes, it wont matter. The space that the old string occupies will be overwritten by the new one.
Note that the question of freeing space does not come up, as you have statically allocated memory. It will be freed only when you exit the program.
--NOTE--
The use of the word 'statically' does not mean that you are declaring any of the variables as static.
is different from
--/NOTE--
Last edited by blowtorch; 10-17-2005 at 10:58 AM..
Reason: fix broken tag
hello sir
since by mentioning a integer pointer and storing the integers
by incrementing the pointer value
then what is the purpose of malloc?
u can decalre it as
in t *p;
several integers can be stored by incrementing the value of p,
hence what is the diffrence between this... (2 Replies)
Some one please explain me what is Dynamic memory allocation and the use of malloc() function.How do we allocate memory dynamically and also the other way? (3 Replies)
Hey Guys
I am trying to implement the malloc function for my OS class and I am having a little trouble with it. I would be really grateful if I could get some hints on this problem.
So I am using a doubly-linked list as my data structure and I have to allocate memory for it (duh...). The... (1 Reply)
Hey Guys
Some of my friends have got together and we are trying to write a basic kernel similar to Linux. I am trying to implement the malloc function in C and I am using a doubly linked list as the primary data structure. I need to allocate memory for this link list (duh...) and I don't feel... (2 Replies)
Why when using realloc, john is reversed 3 times but not the other 2 names ? But if I use malloc, then the 3 names are reversed correctly ? (but then there is a memory leak)
How can I reverse all 3 names without a memory leak ?
char *BUFFER = NULL;
char *STRREVERSE(const char *STRING)
{... (5 Replies)
Hi i found code in google how to malloc an 2D array and i tried that :
#include<stdio.h>
#include<stdlib.h>
int **A;
int **B;
int main(int argc,char *argv)
{
printf("name of text : %s\n",argv);
//read arrays
int i,j;
int l,m;
int M,n;
FILE *fp;
fp=fopen(argv,"r");
... (0 Replies)
Which one is faster among malloc and new?
My understanding is that since new also has to call constructors after allocating memory it must be slower than malloc.
Am I correct? (1 Reply)
Good day! I'm a newbie in C. I'm trying to get an unlimited input from the user using malloc then printing the inputs after the user presses enter. My code works, but there's a warning that I don't know how to fix. Please help me. Thank you.
Here's my code:
#include <stdio.h>
#include... (6 Replies)
Discussion started by: eracav
6 Replies
LEARN ABOUT OSF1
xstr
xstr(1) General Commands Manual xstr(1)NAME
xstr - Extracts strings from C programs to implement shared strings
SYNOPSIS
xstr [-c] [file | -]
The xstr command maintains a file called strings into which strings in component parts of a large program are hashed.
OPTIONS
Extracts strings from the specified file.
DESCRIPTION
The strings extracted by xstr are replaced with references to this array. This serves to implement shared constant strings, most useful if
they are also read-only.
The following command extracts the strings from the C source in file, replacing string references by expressions of the form (&xstr[num-
ber]) for some number. xstr -c file
The xstr command uses file as input; the resulting C text is placed in the file x.c to then be compiled. The strings from this file are
appended to the strings file if they are not there already. Repeated strings and strings that are suffixes of existing strings do not cause
changes to the file.
If a string is a suffix of another string in the file, but the shorter string is seen first by xstr, both strings are placed in the file
strings.
After all components of a large program are compiled, a file xs.c declaring the common xstr space can be created by a command of the fol-
lowing form: xstr
Compile and load this xs.c file with the rest of the program. Some C compilers may, by default, put strings in a read-only text section.
The xstr command can also be used on a single file. The following command creates files x.c and xs.c as before, without using or affecting
a strings file in the same directory. xstr file
It may be useful to run xstr after the C preprocessor if any macro definitions yield strings or if there is conditional code that contains
strings that may not be needed. The xstr command reads from its standard input when the argument - (dash) is given. An appropriate command
sequence for running xstr after the C preprocessor is as follows: cc -E file.c | xstr -c - cc -c x.c mv x.o file.o
The xstr command does not touch the file strings unless new items are added, thus make can avoid remaking xs.o unless truly necessary.
EXAMPLES
To extract the strings from the C source in the file.c parameter, replacing string references by expressions of the form (&xstr[number]),
enter: xstr -c file
An appropriate declaration of the xstr array is prepended to file. The resulting C text is placed in the file x.c, to then be com-
piled. To declare the common xstr array space in the xs.c file, enter: xstr
FILES
File that contains the extracted strings. Modified C source. C source for definition of array xstr. Temporary file when the xstr command
does not touch strings.
SEE ALSO
Commands: mkstr(1)xstr(1)