how do you copy pointers in C..?

wasssup

Diamond Member
Nov 28, 2000
3,142
0
0
so here's the deal...i'm currently working on a multiprocessing program (using fork()) with C, and i pretty much have everything working except this last problem :(

so, the process that's not working properly simply reads strings from a text file, uses strtok to extract all the numbers and throw them into two variables (since there are two integer numbers in each string), but I want to rewrite the text file with the original argument as well as the answer (ie. if the string says "5 + 3" it should rewrite "5 + 3 = 8").

rewind() sends the pointer to the beginning of the file, so that's no good...how would I send the pointer to the beginning of the line?

If I use rewind(), it writes to the file the way I want it to but as mentioned earlier it keeps processing the first line...
If I don't use rewind the output to the screen is correct, but nothing's being rewritten to the files..
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
You'll probbaly have to save the position of the start of line and use fseek or lseek to go back that to that position, write out your data, update your beginning of line pointer for the next line and do it all again.
 

wasssup

Diamond Member
Nov 28, 2000
3,142
0
0
hmm i don't know much about fseek yet, but i'll read up on it...

thanks for the tip
 

oog

Golden Member
Feb 14, 2002
1,721
0
0
i don't quite get what you're trying to do. you're trying to rewrite the file you're reading with new data? so the "5 + 3" text would become "5 + 3 = 8"? if so, you're not going to be able to directly write into the file that you're reading. generally, you cannot insert more data than you are replacing. one solution here is to write a separate file, and then do the appropriate delete/rename operations to make your temporary file replace the original one.
 

Apathetic

Platinum Member
Dec 23, 2002
2,587
6
81
Originally posted by: Nothinman
You'll probbaly have to save the position of the start of line and use fseek or lseek to go back that to that position, write out your data, update your beginning of line pointer for the next line and do it all again.

Yup. That'll work just fine.

Dave