In order to make an algorithm work, I'd like to delete the first line of a text file. I'm having a hard time finding an example for that though. I was thinking that there should be the possibility to delete up to a \n. Could you point me to a solution? Oh, I'm using a standard Arduino Uno

Thank you

  • Is it necessary to re-write the file, or is this a file whose later contents will be read and processed by the Arduino? If the latter, then you can just read and throw away a character at a time until you get to '\n' after you open the file. Commented Apr 3, 2018 at 14:30
  • Well, in this case, the Arduino is connected to Wifi and serves each produced data point as a .csv to a server. I suppose this counts as "processing by Arduino". So what you suggest would work. I'm not sure though how one would go about to "throw away a character". Is there a search term for that, so I can check it out? Thanks! Commented Apr 4, 2018 at 7:45
  • To read the file, you would use fopen() to open it and get a file handle. Then you use fgetc() to read one character at a time and check that character to see if it's '\n'. By "throwing away", I mean that the character you read can just be overwritten by the next one you read -- you don't have to build a string or anything or try to save the character for later in the program. Commented Apr 4, 2018 at 12:35

1 Answer 1


What you can do is:

  • opening a file (to read)
  • opening a new file (to write)
  • since a line can be long (more than arduino's memory), it's best to read it character by character, thus:
  • use a boolean to denote when to start removing a line (set to e.g. Remove = TRUE)
  • For every character you read:
    • If Remove is TRUE, don't write to the output file, otherwise write it
    • If the character is \n or \r (check how line ends are), set the boolean to False (e.g. continue writing)
  • Remove file to read
  • Rename written file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.