Sponsored Content
Top Forums Programming help with char pointer array in C Post 302509232 by omega666 on Wednesday 30th of March 2011 10:42:07 AM
Old 03-30-2011
help with char pointer array in C

i have an array like
Code:
    #define NUM 8
    ....
    new_socket_fd = accept(socket_fd, (struct sockaddr *) &cli_addr, &client_length);
    char *items[NUM] = {"one", "two", "three", "four", "five", "six", "seven", "eight"};
    char *item_name_length[NUM] = {"3", "3", "5", "4", "4", "3", "5", "5"};
    send_items(items, item_name_length, &NUM , &new_socket_fd);

Code:
void send_items(char *items[], char *item_name_length[], int *length, int *new_socket_fd) {
    int i, bytes;
    for(i = 0; i<*length; i++) {
        bytes = write(*new_socket_fd,items[i],atoi(item_name_length[i]));
        if (bytes < 0) error("ERROR writing to socket");
    }
}

and i get this error on the line where i call the function

error: lvalue required as unary â&â operand

whats wrong?
 

10 More Discussions You Might Find Interesting

1. Programming

Regarding char Pointer

Hi, char *s="yamaha"; cout<<s<<endl; int *p; int i=10; p=&i; cout<<p<<endl; 1) For the 1st "cout" we will get "yamaha" as output. That is we are getting "content of the address" for cout<<s. 2) But for integer "cout<<p" we are getting the "address only". Please clarify how we are... (2 Replies)
Discussion started by: sweta
2 Replies

2. UNIX for Dummies Questions & Answers

Storing pointer array in C

All .. I am having a pointer array . And trying to store the addess into that pointer array . please see below the problem i faced code: int cnt1; char *t_array; char *f_array; for(cnt1=0; cnt1<1000; cnt1++) { t_array =... (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

3. Programming

Adding a single char to a char pointer.

Hello, I'm trying to write a method which will return the extension of a file given the file's name, e.g. test.txt should return txt. I'm using C so am limited to char pointers and arrays. Here is the code as I have it: char* getext(char *file) { char *extension; int i, j;... (5 Replies)
Discussion started by: pallak7
5 Replies

4. Programming

How to get the sizeof char pointer

The below code throws the error, since the size of x = 19 is not passed to the cstrCopy function. using namespace std; static void cstrCopy(char *x, const char*y); int main () { char x; const string y = "UNIX FORUM"; cstrCopy(x,y.c_str()); return 0; } void cstrCopy(char *x,... (3 Replies)
Discussion started by: SamRoj
3 Replies

5. Programming

Array of char

I'm doing some coding in C++ Want to have a long empty string like below const char ModMisfit :: DelStr = "\r \r"; However due to the long blank the line is very long. Is there any way to avoid this and keep the... (5 Replies)
Discussion started by: kristinu
5 Replies

6. Programming

C pointer/array duality confusion

Hi all, Can anyone provide help with getting the right syntax regarding array/pointers in C in the following code? Can't locate a specific example which clarifies this... Say I declare a typedef to an array of pointers to some type... /** * An array of ptrs to sections */ typedef... (4 Replies)
Discussion started by: gorga
4 Replies

7. Programming

structure pointer array as function parameters

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

8. Programming

Unclear pointer and array

Hello, The purpose of the program is to print a sub string from the prompt inputs. I do not understand why char pointer does not work but char array will for line 40 and Line 41. ./a.out thisisatest 0 8 substring = "thisisat"And my code is: #include <stdio.h> #include <stdlib.h> #include... (29 Replies)
Discussion started by: yifangt
29 Replies

9. Programming

Pointer for 2D array seems to be 3D in C

I am struggling with the pointer to 2D-array (cf: 2D array of pointers). Can anybody help me elaborate how the pointer x moves in the memory to access the individual of y, especially the high lighted lines? I have talked to one of the curators of the forum, but I am still not quite clear. Here... (1 Reply)
Discussion started by: yifangt
1 Replies

10. Programming

Segmentation fault when I pass a char pointer to a function in C.

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
explain_accept(3)					     Library Functions Manual						 explain_accept(3)

NAME
explain_accept - explain accept(2) errors SYNOPSIS
#include <libexplain/accept.h> const char *explain_accept(int fildes, struct sockaddr *sock_addr, socklen_t *sock_addr_size); const char *explain_errno_accept(int errnum, int fildes, struct sockaddr *sock_addr, socklen_t *sock_addr_size); void explain_message_accept(char *message, int message_size, int fildes, struct sockaddr *sock_addr, socklen_t *sock_addrlen); void explain_message_errno_accept(char *message, int message_size, int errnum, int fildes, struct sockaddr *sock_addr, socklen_t *sock_addr_size); DESCRIPTION
These functions may be used to obtain explanations for errors returned by the accept(2) system call. explain_accept const char *explain_accept(int fildes, struct sockaddr *sock_addr, socklen_t *sock_addr_size); The explain_accept function is used to obtain an explanation of an error returned by the accept(2) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. The errno global variable will be used to obtain the error value to be decoded. This function is intended to be used in a fashion similar to the following example: if (accept(fildes, sock_addr, sock_addr_size) < 0) { fprintf(stderr, "%s ", explain_accept(fildes, sock_addr, sock_addr_size)); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_accept_or_die(3) function. fildes The original fildes, exactly as passed to the accept(2) system call. sock_addr The original sock_addr, exactly as passed to the accept(2) system call. sock_addr_size The original sock_addr_size, exactly as passed to the accept(2) system call. Returns: The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. explain_errno_accept const char *explain_errno_accept(int errnum, int fildes, struct sockaddr *sock_addr, socklen_t *sock_addr_size); The explain_errno_accept function is used to obtain an explanation of an error returned by the accept(2) system call. The least the mes- sage will contain is the value of strerror(errnum), but usually it will do much better, and indicate the underlying cause in more detail. This function is intended to be used in a fashion similar to the following example: if (accept(fildes, sock_addr, sock_addr_size) < 0) { int err = errno; fprintf(stderr, "%s ", explain_errno_accept(err, fildes, sock_addr, sock_addr_size)); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_accept_or_die(3) function. errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces- sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. fildes The original fildes, exactly as passed to the accept(2) system call. sock_addr The original sock_addr, exactly as passed to the accept(2) system call. sock_addr_size The original sock_addr_size, exactly as passed to the accept(2) system call. Returns: The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. explain_message_accept void explain_message_accept(char *message, int message_size, int fildes, struct sockaddr *sock_addr, socklen_t *sock_addr_size); The explain_message_accept function may be used to obtain an explanation of an error returned by the accept(2) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. The errno global variable will be used to obtain the error value to be decoded. This function is intended to be used in a fashion similar to the following example: if (accept(fildes, sock_addr, sock_addr_size) < 0) { char message[3000]; explain_message_accept(message, sizeof(message), fildes, sock_addr, sock_addr_size); fprintf(stderr, "%s ", message); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_accept_or_die(3) function. message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. message_size The size in bytes of the location in which to store the returned message. fildes The original fildes, exactly as passed to the accept(2) system call. sock_addr The original sock_addr, exactly as passed to the accept(2) system call. sock_addr_size The original sock_addr_size, exactly as passed to the accept(2) system call. explain_message_errno_accept void explain_message_errno_accept(char *message, int message_size, int errnum, int fildes, struct sockaddr *sock_addr, socklen_t *sock_addr_size); The explain_message_errno_accept function may be used to obtain an explanation of an error returned by the accept(2) system call. The least the message will contain is the value of strerror(errnum), but usually it will do much better, and indicate the underlying cause in more detail. This function is intended to be used in a fashion similar to the following example: if (accept(fildes, sock_addr, sock_addr_size) < 0) { int err = errno; char message[3000]; explain_message_errno_accept(message, sizeof(message), err, fildes, sock_addr, sock_addr_size); fprintf(stderr, "%s ", message); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_accept_or_die(3) function. message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. message_size The size in bytes of the location in which to store the returned message. errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces- sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. fildes The original fildes, exactly as passed to the accept(2) system call. sock_addr The original sock_addr, exactly as passed to the accept(2) system call. sock_addr_size The original sock_addr_size, exactly as passed to the accept(2) system call. SEE ALSO
accept(2) accept a connection on a socket explain_accept_or_die(3) accept a connection on a socket and report errors COPYRIGHT
libexplain version 0.52 Copyright (C) 2008 Peter Miller explain_accept(3)
All times are GMT -4. The time now is 11:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy