Technology
 

Comment

From Abacus Compiler Wiki

this is my secound aprocht to writing the funktion that takes the comments out of the source bevore it is compiled.. this is more chalenging than i had ecspectde..


this is the source


  1. include <sys/types.h>
  2. include <sys/stat.h>
  3. include <fcntl.h>
  4. include <stdio.h>
  5. include <unistd.h>

//finde this kind of komment /* and find this kinde of comment*/ /* and ignore comments in " -.... - " */ /*and dellet bozh of them and wirte file new*/

main() { int max, fdo, fdn, i, i_n; char old[10000], new[1000], c ;

fdo=open("source.c" ,O_RDONLY); fdn=open("sourceO.c" , O_WRONLY | O_CREAT);

for(max=0; ((c=getc(fdo))!= EOF); max++ ) old[max]=c;

i_n = 0; for(i=0; (i<=max && old[i]=!'\0'); i++){ if (old[i]='/'){ if (old[i++]='/'){ i++; while(old[i]=!'\n') i++; } else if (old[i++]='*'){ i++; while(old[i]=!EOF){ if (old[i]='*') {i++; if (old[i]='/') break; } else i++ ; } } else { new[i_n]=old[i]; i_n++;} } else { new[i_n]=old[i]; i_n++;} }

i_n++ ; new[i_n]='\0';

for(i=0; new[i]=!'\0'; i++) { write(fdn, new[i], 1); }

}



this is waht the compiler says:

uncomentS.c: In Funktion »main«: uncomentS.c:20: Warnung: Übergabe des Arguments 1 von »_IO_getc« erzeugt Zeiger von Ganzzahl ohne Typkonvertierung uncomentS.c:23: Fehler: Ungültiger L-Wert in Zuweisung uncomentS.c:44: Warnung: Übergabe des Arguments 2 von »write« erzeugt Zeiger von Ganzzahl ohne Typkonvertierung