Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple question: File Pointers

Status
Not open for further replies.

willz99ta

IS-IT--Management
Sep 15, 2004
132
US
Howdy,

Thanks for helping a new programmer, I sincerely appreciate it.

I am trying to copy character string information stored in a file pointer to another pointer.

Should I initialize the pointer like
char newPtr[90000]?
(yea the file pointer being copied to it is big!)


And what statement do I use to transfer data from the two pointers?

*newPtr = *inputPtr; ?

Note: I am trying to get around incrementing the file pointer used later in the program.


Thank you for any help,
Willz99ta
 
Basically, everything here is wrong :)
char newPtr[90000] does not declare a pointer. It declares array of char with 90000 elements.
The pointer points (hah, smart remark) at some address in memory. If you want two pointers, say p1 and p2 to point at the same address just use equation - p1=p2.
I'm not sure what you're trying to do but I guess you want to copy name of the file pointed to by inputPtr to array of char - you can't do that (I think).
Write something more about what you want to do.
 
char newPtr[90000];
char *ptrarry = newPtr;
char *memptr;
char *ptrarryfifth = &newPtr[4];

newPtr is an array of 90000 bytes.
strcpy(newPtr,"This is data"); // copies string to array
strcpy(ptrarry,"This is data"); // copies string to array
// as above
strcpy(ptrarryfifth,"Starts data in pos 5");

and
// dynamically assigns space at run time
memptr = (char *)malloc(90000);
if (!memptr) have an error - always check
strcpy(memptr,"This is data");
strcpy((memptr+4),"Starts data in pos 5"); or
memptr = memptr+4;
strcpy(memptr,"Starts data in pos 5");
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top