![]() |
|
#1
|
|||
|
|||
convert long to pointer to charHello all,
I have created a function which accepts a pointer to a char array (unsigned char *insert) and inserts the corresponding byte values into a file at a specified position(unsigned long pos) with length(unsigned long insertlen). this appears to work ok. Does such a routine already exist ? this is part of a much larger program to build a database of repeating words/sequences in a file and their corresponding file positions. . . . . . . However, I also need to insert a long into positions within the file, so I tried to convert it to a pointer to a char array, which is where errors occur, either in conversion or when *longvar is passed into the insertintofile function: unsigned char *longvar=reinterpret_cast<unsigned char*>(wordpos); //wordpos=long var of file position of sequence This is the insertintofile function: CPP / C++ / C Code:
thanks Gary |
|||
|
#2
|
|||
|
|||
|
Hey Gary, welcome to the boards.
Sounds like you need to convert a long int to a string (you're sticking to C stylee). Sounds like a ltoa() function, if only it was in the C standard lib! However, the good networthy folk have made reinventing the wheel an infrequent task. Here is a good looking ltoa() function, courtesy of ftp.osterman.com CPP / C++ / C Code:
Haven't tested it myself, so finger crossed! GF |
|
#3
|
|||
|
|||
|
Hi Garth,
thanks for your reply. The ltoa function seems to use an incredible amount of code (much of which I don't really understand) to do what I thought was a fairly simple reassignment. Anyway, all I needed to do was when converting the original unsigned long, refer to it by reference ie. CPP / C++ / C Code:
This now does exactly what I want. Is my insertintofile function 'acceptable' or do you know of a more efficient method ? Gary |
Recent GIDBlog
Programming ebook direct download available by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| i/o: set value x (long) before it is used by a function | gmn | C Programming Language | 1 | 18-Nov-2003 02:12 |
| storing a token pointer as a string | CoreLEx | C Programming Language | 1 | 07-Oct-2003 12:33 |
| char to operator | calculus87 | C++ Forum | 3 | 04-Sep-2003 11:05 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The