How to modify a column of a .txt with c ++?

0

I am working on a program to convert files in .PCD format to .OFF format, for which I need to read the file. It's like reading a .txt and deleting the header but additionally deleting the 4 column of data, until now I have managed to eliminate the header but I can not delete the fourth column.

The format is something like this:

 #.PCD v.7 - Point Cloud Data file format  
VERSION .7  
FIELDS x y z rgb  
SIZE 4 4 4 4  
TYPE F F F F  
COUNT 1 1 1 1  
WIDTH 213  
HEIGHT 1  
VIEWPOINT 0 0 0 1 0 0 0  
POINTS 213  
DATA ascii  
0.93773 0.33763 0 4.2108e+06  
0.90805 0.35641 0 4.2108e+06  
0.81915 0.32 0 4.2108e+06  
0.97192 0.278 0 4.2108e+06  
0.944 0.29474 0 4.2108e+06  
0.98111 0.24247 0 4.2108e+06  
0.93655 0.26143 0 4.2108e+06  
0.91631 0.27442 0 4.2108e+06  
0.81921 0.29315 0 4.2108e+06   
0.90701 0.24109 0 4.2108e+06  
0.83239 0.23398 0 4.2108e+06  
0.99185 0.2116 0 4.2108e+06  
0.89264 0.21174 0 4.2108e+06  
0.85082 0.21212 0 4.2108e+06  
0.81044 0.32222 0 4.2108e+06  
0.74459 0.32192 0 4.2108e+06  
0.69927 0.32278 0 4.2108e+06  
0.8102 0.29315 0 4.2108e+06  
0.75504 0.29765 0 4.2108e+06  

The fourth column that I need to eliminate is the one that starts with the 4th.

and the code I have to delete the header is this:

#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <iostream>
#include<stdlib.h>
#include<string.h>
#include<fstream>
using namespace std;
int main()
{
int archivo;
char caracter;
long tamanno_archivo;

archivo=open("prueba.pcd", O_RDWR | O_BINARY);
if(archivo==-1) printf("Error al abrir archivo.\n");
tamanno_archivo=filelength(archivo);
for(long pos=1; pos<tamanno_archivo; pos++)
{
lseek(archivo, pos, 0);
read(archivo, &caracter, sizeof(char));
lseek(archivo, pos-185, 0);
write(archivo, &caracter, sizeof(char));
}
chsize(archivo, tamanno_archivo-185);
close(archivo);
}

Thank you in advance.

    
asked by Andres Montenegro 09.09.2018 в 18:07
source

1 answer

0

To begin with, since you have labeled your question as C ++, you should use the language correctly:

answered by 10.09.2018 / 10:40
source