Saeed
Saeed

Reputation: 35

write between two characters in C

I have a very big text file and I am writing code that tries to find all '' (two single quotation marks in a row) and then write a number between these two single quotation marks. Can I do this in C? I am using a pointer to find the '' . Thank you.

letter1 = fgetc(fptr);
if(letter1=="'"){
  fseek(fptr, 1, SEEK_CUR); 
  letter2=fgetc(fptr);
  if(letter=="'"){

  }
}
else{
  fseek(fptr, 1, SEEK_CUR);
}

Upvotes: 0

Views: 118

Answers (1)

Petr Skocik
Petr Skocik

Reputation: 60097

Most programs (I've come across) write out a new file and replace the old one with it. You can do it in place, but you're going to have to move the bytes after where you want to insert to prevent overwriting. The mmap, mremap functions might help you turn it into a memmove operation if you're on a POSIX system.

Upvotes: 1

Related Questions