09-16-2011
Quote:
Originally Posted by
zius_oram
got it
thank you so much. do C through segfault for any particular type of error?? i wanna know when exactly C throws segfault?
segfault is one kind of runtime error and there can be a number of reasons for it...the most common ones are buffer overruns or stepping into memory which is read only or dereferencing an invalid address pointer.
This User Gave Thanks to shamrock For This Post:
10 More Discussions You Might Find Interesting
1. Programming
i am having a string like
" X1 " ---> string lenght is 30
I have stored this to a chararry . ref
so here ref = " X1 "
now i trim the left space by my function . Si the string now becomes
"X1 " ---> string lenght is 15... (3 Replies)
Discussion started by: arunkumar_mca
3 Replies
2. Programming
If one wants to get a start address of a array or a string or a block of memory via a function, there are at least two methods to achieve it:
(1) one is to pass a pointer-to-pointer parameter, like:
int my_malloc(int size, char **pmem)
{
*pmem=(char *)malloc(size);
if(*pmem==NULL)... (11 Replies)
Discussion started by: aaronwong
11 Replies
3. Programming
Hello everyone,
I'm writing a program using the id3lib unfortunately I've encountered with memory issue that cause segmentation fault. I tried to rerun and analyze the program with valgrind but it doesn't point me anywhere. I really stuck on this one.
Valgrind output:
==14716== Invalid read of... (2 Replies)
Discussion started by: errb
2 Replies
4. Programming
Hi,
Can any one tell me why my following program is crashing?
#include <iostream>
using namespace std;
class CA {
public:
const static int i;
};
const int CA::i = 10;
int main() {
int* pi = const_cast<int*>(&CA::i);
*pi = 9;
cout << CA::i << endl;
} (6 Replies)
Discussion started by: royalibrahim
6 Replies
5. UNIX for Dummies Questions & Answers
I'm trying to write a programme which scans strings to find how many vowels they contain. I get an error saying that I'm trying to compare a pointer and an integer inif(*v == scanme){. How can I overcome this ? Also, the programme seems to scan only the first word of a string e.g.: if I type "abc... (1 Reply)
Discussion started by: fakuse
1 Replies
6. Programming
I'm newbie learner. My all friend use windows just only me use linux.
so i can't solve any problem by myself. i need a solution.
how can i use pointer as a string.
#include<string.h>
#include<stdio.h>
int main()
{
char *s='\0';
gets(s);
puts(s);
return 0;
}
This code work on... (6 Replies)
Discussion started by: raihan004
6 Replies
7. Programming
I am populating an array of string and print it.
But it going in infinite loop and causing segfault.
char Name = {
"yahoo",
"rediff",
"facebook",
NULL
};
main(int argc, char* argv)
{
int j = 0;
... (7 Replies)
Discussion started by: rupeshkp728
7 Replies
8. Programming
I have a problem with scanf() for string pointer as member of a struct.
#include <stdio.h>
#include <stdlib.h>
struct Student {
int studentNumber;
int phoneNumber;
char *studentName; //line 7
// char studentName; //line 8
};
int... (10 Replies)
Discussion started by: yifangt
10 Replies
9. Programming
Hello, I am trying to reverse complement one string and reverse another (NO complement!), both with pointer. My code compiled without error, but did not do the job I wanted.
#include <stdio.h>
#include <stdlib.h>
#include <zlib.h>
#include "kseq.h"
// STEP 1: declare the type of file... (5 Replies)
Discussion started by: yifangt
5 Replies
10. Programming
Another project, another bump in the road and another chance to learn. I've been trying to open gzipped files and parse data from them and hit a snag. I have data in gzips with a place followed by an ip or ip range sort of like this:
Some place:x.x.x.x-x.x.x.x
I was able to modify some code... (6 Replies)
Discussion started by: Azrael
6 Replies
LEARN ABOUT ULTRIX
xtmalloc
XtMalloc(3Xt) MIT X11R4 XtMalloc(3Xt)
Name
XtMalloc, XtCalloc, XtRealloc, XtFree, XtNew, XtNewString - memory management functions
Syntax
char *XtMalloc(size);
Cardinal size;
char *XtCalloc(num, size);
Cardinal num;
Cardinal size;
char *XtRealloc(ptr, num);
char *ptr;
Cardinal num;
void XtFree(ptr);
char *ptr;
type *XtNew(type);
type;
String XtNewString(string);
String string;
Arguments
num Specifies the number of bytes or array elements.
ptr Specifies a pointer to the old storage or to the block of storage that is to be freed.
size Specifies the size of an array element (in bytes) or the number of bytes desired.
string Specifies a previously declared string.
type Specifies a previously declared data type.
Description
The functions returns a pointer to a block of storage of at least the specified size bytes. If there is insufficient memory to allocate
the new block, calls
The function allocates space for the specified number of array elements of the specified size and initializes the space to zero. If there
is insufficient memory to allocate the new block, calls
The function changes the size of a block of storage (possibly moving it). Then, it copies the old contents (or as much as will fit) into
the new block and frees the old block. If there is insufficient memory to allocate the new block, calls If ptr is NULL, allocates the new
storage without copying the old contents; that is, it simply calls
The function returns storage and allows it to be reused. If ptr is NULL, returns immediately.
returns a pointer to the allocated storage. If there is insufficient memory to allocate the new block, calls is a convenience macro that
calls with the following arguments specified:
((type *) XtMalloc((unsigned) sizeof(type))
returns a pointer to the allocated storage. If there is insufficient memory to allocate the new block, calls is a convenience macro that
calls with the following arguments specified:
(strcpy(XtMalloc((unsigned) strlen(str) + 1), str))
See Also
X Window System Toolkit: The Complete Programmer's Guide and Specification, Paul J. Asente and Ralph Swick
X Window System: The Complete Reference, Second Edition, Robert W. Scheifler and James Gettys
XtMalloc(3Xt)