c++ - I am trying to clean my data file from special charachters with some conditions, but those conditions are not met? -


ok here code

this code trying remove special characters ",',{,},(,) .txt file , replace them blank space.

#include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <string.h> #include <stdio.h> #include <fcntl.h> #include <iostream> #include <time.h> #include <fstream>  using namespace std; int main(int argc, char *argv[]) {     int fd;     int i;     int j;     int len;     int count = 0;     int countcoma = 0;     int countquote = 0;     char buf[10];     char spec[] = {',','"',':','{','}','(',')','\''};      fd = open(argv[1],o_rdwr,0777);      while (read(fd,buf,10) != 0) {         len = strlen(buf);         (i=0;i<len;i++) {             (j=0;j<8;j++) {                 if (buf[i]==spec[j]) {                     count =1;                     countquote=0;                     if (j==1) {                         if (countcoma == 0) {                             countcoma++;                         }                         if (countcoma == 1) {                             countcoma--;                         }                     }                     if ((j==7) && (countcoma ==1)) {                                 countquote = 1;                     }                     break;                 }             }             //cout<<countquote;             if ((count != 0) && (countquote == 0)) {                 buf[i] = ' ';             }             count = 0;               }         lseek(fd, -sizeof(buf), seek_cur);         write(fd,buf,sizeof(buf));         memset(buf,' ',10);     }      return 0; } 

now want single quotes inside double quotes in file remain untouched, special characters replaced space mentioned in code. want these kind of single quotes remain untouched "what's" after run file becomes s instead of what's

ok, problem code doing 1 thing, undo in next section. in particular:

                    if (countcoma == 0) {                         countcoma++;                     }                     if (countcoma == 1) {                         countcoma--;                     } 

follow logic: come in countcoma zero. first if true, , gets incremented. 1. next if says if (countcoma == 1) true, , decrement it.

i replaced countcoma = !countcoma; simpler way "if it's 0, make 1, if it's 1, make 0. put anelseon of firstif` make same thing.

there whole bunch of stylistic things: example hard-coded constants, writing original file (means if there bug, lose original file - thing didn't close editor window sample file...), including half universe in header files, , figuring of spec characters based on index.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -