Â
I have a 550 lines written .txt file. I want to take out the last character from every line. Thre is also a space between each line that I want to remove. Can anyone tell me the code or script how to go on about doing so?
Answered By
points
N/A
#131938
Remove last character from each line in a text file
Hello,
Removing last character from each line can be done easily using the following C program. Just compile and run:
int main(int argc, char * argv[])
{
   FILE * InputFile;
   off_t position;
       int charsToDelete;
Â
   if ((InputFile = fopen(argv[1],"r+")) == NULL)
   {
           printf("tdes: file not found: %sn",argv[1]);
   }
   else
   {
               charsToDelete = 5;
       fseeko(InputFile,-charsToDelete,SEEK_END);
       position = ftello(InputFile);
       printf("Pos: %dn",(int)position);
       int i;
       //for(i = 0;i < charsToDelete;i++)
       //{
       // putc(InputFile,'b');
       //}
   }
   fclose(InputFile);
   return 0;
}