Sponsored Content
Top Forums Programming Problem with array of pointers Post 302384859 by lovevijay03 on Wednesday 6th of January 2010 01:25:31 PM
Old 01-06-2010
Question Problem with array of pointers

Hi All,

I am using the array of pointers and storing the address of string.This is a global list.
So i am using extern to give the reference of this list to another file and using reading the data from this string.
But list is being corrupted and string is missing some characters in string. eg.

In file A:

Code:
char *str[512]; 
char line[512];  

while(fgets(line, 512, fp) != NULL) str[count++] = line;

in file B:

Code:
char* alert; 
for(i = 0 ; i < count; count++) alert = str;

Anyone can suggest me why it is being corrupted.that would be appreciated. It's crashing also in gcc for linux and but not solaris.

Thanks!

Last edited by Franklin52; 01-06-2010 at 02:48 PM.. Reason: Adding code tags and reformat code and text
 

10 More Discussions You Might Find Interesting

1. Programming

Pointers and array

hi all, let say i have a pointer exit, and this exit will store some value. how can i store the value that the pointer points to into an array and then print them out from the array. thanks in advance (2 Replies)
Discussion started by: dianazheng
2 Replies

2. Shell Programming and Scripting

array problem

Dear Experts, please help me out once again my array concepts is not very clear i have one text file like. 1|usa|hh 2|usa|ll 3|usa|vg 4|uk|nn 5|uk|bb 6|kuwait|mm 6|kuwait|jkj 7|dubai|hh i want to store the third fied of a text file in he array and after that it should give me some... (6 Replies)
Discussion started by: shary
6 Replies

3. Programming

Problem with pointers, structures, and Pthread

Hello all, I'm working on a small wrapper library for a bigger project, and i've been killing my self over (what I think is) a pointer problem. Here is the code (I extracted the part of the code where the problem is for better reading, I tested the code below, and I get the same problem):... (13 Replies)
Discussion started by: tmp0
13 Replies

4. Shell Programming and Scripting

Array problem

I am using /bin/ksh for this problem. I have created some arrays with variable names as the array names: cnt=1 { while read myline; do tempmeas="${meas%%;*}" cto="${meas#*;}" tempstream=$stream # wholemeas holds the name of the array # each array name... (0 Replies)
Discussion started by: ajgwin
0 Replies

5. Programming

Help on some array problem!!

i have no idea how to make a text file abc efg hij klm nop qrs to be a array such as, arr to be "abc efg" arr "hij kml" etc..... in C (2 Replies)
Discussion started by: tyckelvin1
2 Replies

6. Programming

Traversing in Array of pointers

Please find the below program. the requirement and description of the program also given: ganesh@ubuntu:~/my_programs/c/letusc/chap9$ cat fa.c.old /* Program : write a program to count the number of 'e' in thefollowing array of pointers to strings: char *s = { "We will teach you how... (12 Replies)
Discussion started by: ramkrix
12 Replies

7. Programming

Problem With Pointers

Hi guys. What is the difference between these: 1. int *a; 2. int (*a); (2 Replies)
Discussion started by: majid.merkava
2 Replies

8. Programming

Passing Pointers by reference in C++ Problem

Hello All, I am having this issue...where I am actually having hard time understanding the problem: The code is as follows: #include<iostream.h> void fxn(char*** var) { int i =4; *var = (char**)malloc(i*sizeof(char*)); for(int j =0; j<4; j++) { *var = "name"; cout<<*var;... (6 Replies)
Discussion started by: mind@work
6 Replies

9. Programming

Pointers and array

Hello, I read from a book exercise for a challenge. How to print out each letter of char array a by two different pointers pa and ppa in the example? I have tried my code for letter "r" by testing without full understanding as only the first one worked. #include<stdio.h> int main() { char... (17 Replies)
Discussion started by: yifangt
17 Replies

10. Programming

How to Declare an array of function pointers?

I am attempting to create an array of function pointers. The examples I follow to do this are from: support.microsoft.com/en-us/help/30580/how-to-declare-an-array-of-pointers-to-functions-in-visual-c ... (3 Replies)
Discussion started by: spflanze
3 Replies
Tcl_ListObj(3)						      Tcl Library Procedures						    Tcl_ListObj(3)

__________________________________________________________________________________________________________________________________________________

NAME
Tcl_ListObjAppendList, Tcl_ListObjAppendElement, Tcl_NewListObj, Tcl_SetListObj, Tcl_ListObjGetElements, Tcl_ListObjLength, Tcl_ListObjIn- dex, Tcl_ListObjReplace - manipulate Tcl objects as lists SYNOPSIS
#include <tcl.h> int Tcl_ListObjAppendList(interp, listPtr, elemListPtr) int Tcl_ListObjAppendElement(interp, listPtr, objPtr) Tcl_Obj * Tcl_NewListObj(objc, objv) Tcl_SetListObj(objPtr, objc, objv) int Tcl_ListObjGetElements(interp, listPtr, objcPtr, objvPtr) int Tcl_ListObjLength(interp, listPtr, intPtr) int Tcl_ListObjIndex(interp, listPtr, index, objPtrPtr) int Tcl_ListObjReplace(interp, listPtr, first, count, objc, objv) ARGUMENTS
Tcl_Interp *interp (in) If an error occurs while converting an object to be a list object, an error message is left in the interpreter's result object unless interp is NULL. Tcl_Obj *listPtr (in/out) Points to the list object to be manipulated. If listPtr does not already point to a list object, an attempt will be made to convert it to one. Tcl_Obj *elemListPtr (in/out) For Tcl_ListObjAppendList, this points to a list object containing elements to be appended onto listPtr. Each element of *elemListPtr will become a new element of listPtr. If *elemListPtr is not NULL and does not already point to a list object, an attempt will be made to convert it to one. Tcl_Obj *objPtr (in) For Tcl_ListObjAppendElement, points to the Tcl object that will be appended to listPtr. For Tcl_SetListObj, this points to the Tcl object that will be converted to a list object containing the objc elements of the array referenced by objv. int *objcPtr (in) Points to location where Tcl_ListObjGetElements stores the number of element objects in listPtr. Tcl_Obj ***objvPtr (out) A location where Tcl_ListObjGetElements stores a pointer to an array of pointers to the element objects of listPtr. int objc (in) The number of Tcl objects that Tcl_NewListObj will insert into a new list object, and Tcl_ListOb- jReplace will insert into listPtr. For Tcl_SetListObj, the number of Tcl objects to insert into objPtr. Tcl_Obj *const objv[] (in) An array of pointers to objects. Tcl_NewListObj will insert these objects into a new list object and Tcl_ListObjReplace will insert them into an existing listPtr. Each object will become a sep- arate list element. int *intPtr (out) Points to location where Tcl_ListObjLength stores the length of the list. int index (in) Index of the list element that Tcl_ListObjIndex is to return. The first element has index 0. Tcl_Obj **objPtrPtr (out) Points to place where Tcl_ListObjIndex is to store a pointer to the resulting list element object. int first (in) Index of the starting list element that Tcl_ListObjReplace is to replace. The list's first ele- ment has index 0. int count (in) The number of elements that Tcl_ListObjReplace is to replace. _________________________________________________________________ DESCRIPTION
Tcl list objects have an internal representation that supports the efficient indexing and appending. The procedures described in this man page are used to create, modify, index, and append to Tcl list objects from C code. Tcl_ListObjAppendList and Tcl_ListObjAppendElement both add one or more objects to the end of the list object referenced by listPtr. Tcl_ListObjAppendList appends each element of the list object referenced by elemListPtr while Tcl_ListObjAppendElement appends the single object referenced by objPtr. Both procedures will convert the object referenced by listPtr to a list object if necessary. If an error occurs during conversion, both procedures return TCL_ERROR and leave an error message in the interpreter's result object if interp is not NULL. Similarly, if elemListPtr does not already refer to a list object, Tcl_ListObjAppendList will attempt to convert it to one and if an error occurs during conversion, will return TCL_ERROR and leave an error message in the interpreter's result object if interp is not NULL. Both procedures invalidate any old string representation of listPtr and, if it was converted to a list object, free any old internal repre- sentation. Similarly, Tcl_ListObjAppendList frees any old internal representation of elemListPtr if it converts it to a list object. After appending each element in elemListPtr, Tcl_ListObjAppendList increments the element's reference count since listPtr now also refers to it. For the same reason, Tcl_ListObjAppendElement increments objPtr's reference count. If no error occurs, the two procedures return TCL_OK after appending the objects. Tcl_NewListObj and Tcl_SetListObj create a new object or modify an existing object to hold the objc elements of the array referenced by objv where each element is a pointer to a Tcl object. If objc is less than or equal to zero, they return an empty object. The new object's string representation is left invalid. The two procedures increment the reference counts of the elements in objc since the list object now refers to them. The new list object returned by Tcl_NewListObj has reference count zero. Tcl_ListObjGetElements returns a count and a pointer to an array of the elements in a list object. It returns the count by storing it in the address objcPtr. Similarly, it returns the array pointer by storing it in the address objvPtr. The memory pointed to is managed by Tcl and should not be freed or written to by the caller. If the list is empty, 0 is stored at objcPtr and NULL at objvPtr. If listPtr is not already a list object, Tcl_ListObjGetElements will attempt to convert it to one; if the conversion fails, it returns TCL_ERROR and leaves an error message in the interpreter's result object if interp is not NULL. Otherwise it returns TCL_OK after storing the count and array pointer. Tcl_ListObjLength returns the number of elements in the list object referenced by listPtr. It returns this count by storing an integer in the address intPtr. If the object is not already a list object, Tcl_ListObjLength will attempt to convert it to one; if the conversion fails, it returns TCL_ERROR and leaves an error message in the interpreter's result object if interp is not NULL. Otherwise it returns TCL_OK after storing the list's length. The procedure Tcl_ListObjIndex returns a pointer to the object at element index in the list referenced by listPtr. It returns this object by storing a pointer to it in the address objPtrPtr. If listPtr does not already refer to a list object, Tcl_ListObjIndex will attempt to convert it to one; if the conversion fails, it returns TCL_ERROR and leaves an error message in the interpreter's result object if interp is not NULL. If the index is out of range, that is, index is negative or greater than or equal to the number of elements in the list, Tcl_ListObjIndex stores a NULL in objPtrPtr and returns TCL_OK. Otherwise it returns TCL_OK after storing the element's object pointer. The reference count for the list element is not incremented; the caller must do that if it needs to retain a pointer to the element. Tcl_ListObjReplace replaces zero or more elements of the list referenced by listPtr with the objc objects in the array referenced by objv. If listPtr does not point to a list object, Tcl_ListObjReplace will attempt to convert it to one; if the conversion fails, it returns TCL_ERROR and leaves an error message in the interpreter's result object if interp is not NULL. Otherwise, it returns TCL_OK after replac- ing the objects. If objv is NULL, no new elements are added. If the argument first is zero or negative, it refers to the first element. If first is greater than or equal to the number of elements in the list, then no elements are deleted; the new elements are appended to the list. count gives the number of elements to replace. If count is zero or negative then no elements are deleted; the new elements are sim- ply inserted before the one designated by first. Tcl_ListObjReplace invalidates listPtr's old string representation. The reference counts of any elements inserted from objv are incremented since the resulting list now refers to them. Similarly, the reference counts for any replaced objects are decremented. Because Tcl_ListObjReplace combines both element insertion and deletion, it can be used to implement a number of list operations. For example, the following code inserts the objc objects referenced by the array of object pointers objv just before the element index of the list referenced by listPtr: result = Tcl_ListObjReplace(interp, listPtr, index, 0, objc, objv); Similarly, the following code appends the objc objects referenced by the array objv to the end of the list listPtr: result = Tcl_ListObjLength(interp, listPtr, &length); if (result == TCL_OK) { result = Tcl_ListObjReplace(interp, listPtr, length, 0, objc, objv); } The count list elements starting at first can be deleted by simply calling Tcl_ListObjReplace with a NULL objvPtr: result = Tcl_ListObjReplace(interp, listPtr, first, count, 0, NULL); SEE ALSO
Tcl_NewObj, Tcl_DecrRefCount, Tcl_IncrRefCount, Tcl_GetObjResult KEYWORDS
append, index, insert, internal representation, length, list, list object, list type, object, object type, replace, string representation Tcl 8.0 Tcl_ListObj(3)
All times are GMT -4. The time now is 02:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy