10-28-2005
Your other post implies you may be passing back a string.
You may prefer to use strcpy like so:
char CountryName[XX*];
strcpy(CountryName, pcCityIdToCountryName(..................) );
*where XX is the size of the string.
The reason being is that you don't know if the char pointer being passed back is still pointing to an allocated memory block. Sometimes I have seen functions pass back a pointer to a local variable or memory being allocated and then made free. It just so happens that you are pointing to a memory location that still has a string (null terminated) value. This may not be the case later on in the program's execution, especially when you are allocating and freeing memory frequently, and you may encounter a memory violation.
At least by copying string into a local variable you can protect against any future problems.
Of course, if it is your own function, you can make your own judgements as to the best way to call it, based on your overall design.
10 More Discussions You Might Find Interesting
1. Programming
could any one tell why the following is showing segmentation fault while using **ptr
but working fine using **a
#include<stdio.h>
... (1 Reply)
Discussion started by: useless79
1 Replies
2. Programming
Hello all
im trying to build function that will return void function pointer
what is mean is ( not working )
the main function
void * myClass::getFunction(int type){
if(type==1)
return &myClass::Test1;
if(type==2)
return &myClass::Test2;
}
void myClass::Test1(){... (1 Reply)
Discussion started by: umen
1 Replies
3. 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
4. Programming
Hi.
Problem: I have to parse the payload of a packet. The payload could be in Big Endian Format (network byte order) or little. That depends on a flag present in the header of the packet.
Solution: A horrible solution could be to check for that flag everytime I have to read a field in the... (11 Replies)
Discussion started by: emitrax
11 Replies
5. Programming
Hi guys.
how a functions such fdopen, ... can return pointer?
are these functions use static memory(variables)? (6 Replies)
Discussion started by: majid.merkava
6 Replies
6. Programming
if i create an array of pointers to a structure "struct node" as:
struct node *r;
and create "n" number of "linked lists" and assign it to the various struct pointers r using some function with a return type as structure pointer as:
r=multiplty(.......) /*some parameters*/
is... (2 Replies)
Discussion started by: mscoder
2 Replies
7. Programming
Hi,
In the below C code,
#include <stdio.h>
void print() {
printf("Hello\n");
}
int main() {
void (*f)() = (void (*)()) print;
f();
(*f)();
}
I wonder, how the syntaxes "f()" and "(*f)()" are treated as same without any error? Is this an improvement or ANSI/ISO... (1 Reply)
Discussion started by: royalibrahim
1 Replies
8. Programming
Does anyone know?
int x = 1;
int *p = &++x; //ok !
int *q = &x++; //gives an error :O
why the first pointer is ok but the second is an error? (13 Replies)
Discussion started by: nishrestha
13 Replies
9. Programming
Have difficulty to understand this pure C code to only print vowels twice from input string. Questions are commented at the end of each place.
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
/*
*Demonstrate the use of dispatch tables
*/
/*Print a char... (11 Replies)
Discussion started by: yifangt
11 Replies
10. Programming
I am passing a char* to the function "reverse" and when I execute it with gdb I get:
Program received signal SIGSEGV, Segmentation fault.
0x000000000040083b in reverse (s=0x400b2b "hello") at pointersExample.c:72
72 *q = *p;
Attached is the source code.
I do not understand why... (9 Replies)
Discussion started by: jose_spain
9 Replies
LEARN ABOUT DEBIAN
ne_get_response_header
NE_GET_RESPONSE_HEAD(3) neon API reference NE_GET_RESPONSE_HEAD(3)
NAME
ne_get_response_header, ne_response_header_iterate - functions to access response headers
SYNOPSIS
#include <ne_request.h>
const char *ne_get_response_header(ne_request *request, const char *name);
void *ne_response_header_iterate(ne_request *request, void *cursor, const char **name, const char **value);
DESCRIPTION
To retrieve the value of a response header field, the ne_get_response_header function can be used, and is given the name of the header to
return.
To iterate over all the response headers returned, the ne_response_header_iterate function can be used. This function takes a cursor
parameter which should be NULL to retrieve the first header. The function stores the name and value of the next header header in the name
and value parameters, and returns a new cursor pointer which can be passed to ne_response_header_iterate to retrieve the next header.
RETURN VALUE
ne_get_response_header returns a string, or NULL if no header with that name was given. If used during request processing, the return value
pointer is valid only until the next call to ne_begin_request, or else, until the request object is destroyed.
Likewise, the cursor, names, and values returned by ne_response_header_iterate are only valid until the next call to ne_begin_request or
until the request object is destroyed.
EXAMPLES
The following code will output the value of the Last-Modified header for a resource:
ne_request *req = ne_request_create(sess, "GET", "/foo.txt");
if (ne_request_dispatch(req) == NE_OK) {
const char *mtime = ne_get_response_header(req, "Last-Modified");
if (mtime) {
printf("/foo.txt has last-modified value %s
", mtime);
}
}
ne_request_destroy(req);
SEE ALSO
ne_request_create, ne_request_destroy.
AUTHOR
Joe Orton <neon@lists.manyfish.co.uk>
Author.
COPYRIGHT
neon 0.29.6 3 May 2011 NE_GET_RESPONSE_HEAD(3)