09-16-2011
got it
thank you so much. do C through segfault for any particular type of error?? i wanna know when exactly C throws segfault?
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 SUSE
basename
BASENAME(3) Linux Programmer's Manual BASENAME(3)
NAME
basename, dirname - parse pathname components
SYNOPSIS
#include <libgen.h>
char *dirname(char *path);
char *basename(char *path);
DESCRIPTION
Warning: there are two different functions basename() - see below.
The functions dirname() and basename() break a null-terminated pathname string into directory and filename components. In the usual case,
dirname() returns the string up to, but not including, the final '/', and basename() returns the component following the final '/'. Trail-
ing '/' characters are not counted as part of the pathname.
If path does not contain a slash, dirname() returns the string "." while basename() returns a copy of path. If path is the string "/",
then both dirname() and basename() return the string "/". If path is a NULL pointer or points to an empty string, then both dirname() and
basename() return the string ".".
Concatenating the string returned by dirname(), a "/", and the string returned by basename() yields a complete pathname.
Both dirname() and basename() may modify the contents of path, so it may be desirable to pass a copy when calling one of these functions.
These functions may return pointers to statically allocated memory which may be overwritten by subsequent calls. Alternatively, they may
return a pointer to some part of path, so that the string referred to by path should not be modified or freed until the pointer returned by
the function is no longer required.
The following list of examples (taken from SUSv2) shows the strings returned by dirname() and basename() for different paths:
path dirname basename
"/usr/lib" "/usr" "lib"
"/usr/" "/" "usr"
"usr" "." "usr"
"/" "/" "/"
"." "." "."
".." "." ".."
RETURN VALUE
Both dirname() and basename() return pointers to null-terminated strings. (Do not pass these pointers to free(3).)
CONFORMING TO
POSIX.1-2001.
NOTES
There are two different versions of basename() - the POSIX version described above, and the GNU version, which one gets after
#define _GNU_SOURCE
#include <string.h>
The GNU version never modifies its argument, and returns the empty string when path has a trailing slash, and in particular also when it is
"/". There is no GNU version of dirname().
With glibc, one gets the POSIX version of basename() when <libgen.h> is included, and the GNU version otherwise.
BUGS
In the glibc implementation of the POSIX versions of these functions they modify their argument, and segfault when called with a static
string like "/usr/". Before glibc 2.2.1, the glibc version of dirname() did not correctly handle pathnames with trailing '/' characters,
and generated a segfault if given a NULL argument.
EXAMPLE
char *dirc, *basec, *bname, *dname;
char *path = "/etc/passwd";
dirc = strdup(path);
basec = strdup(path);
dname = dirname(dirc);
bname = basename(basec);
printf("dirname=%s, basename=%s
", dname, bname);
SEE ALSO
basename(1), dirname(1), feature_test_macros(7)
COLOPHON
This page is part of release 3.25 of the Linux man-pages project. A description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
GNU
2009-03-30 BASENAME(3)