Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Napisz program, który odczyta swój kod źródłowy i wypisze na ekranie wyłącznie umieszczone w nim komentarze.
- */
- #include <stdio.h>
- #include <string.h>
- #define BUFFER_SIZE 1024
- void read_buffer(char *buffer, unsigned long size)
- {
- for(int i = 0; i < size; i++){
- printf("%c", buffer[i]);
- }
- }
- void odczytaj_kod_zrodlowy(FILE *plik)
- {
- char tmp;
- char tmp_next = getc(plik);
- while(!feof(plik)){
- char buffer[BUFFER_SIZE];
- tmp = tmp_next;
- tmp_next = getc(plik);
- //KOMENTARZ1
- //KOMENTARZ2
- if(tmp_next != EOF){
- if((tmp == '/') && (tmp_next == '/')) {
- fgets(buffer, BUFFER_SIZE, plik);
- printf("%s", buffer);
- }
- if((tmp == '/' && tmp_next == '*')) {
- int i = 0;
- while(!((tmp == '*') && (tmp_next == '/'))) {
- tmp = tmp_next;
- tmp_next = getc(plik);
- buffer[i] = tmp_next;
- i++;
- }
- //KOMENTARZ3
- read_buffer(buffer, strlen(buffer)-2);
- memset(buffer, 0, BUFFER_SIZE);
- }
- }
- }
- printf("\n");
- }
- int main(int argc, char *argv[])
- {
- FILE *kod_zrodlowy;
- kod_zrodlowy = fopen("main.c", "r");
- if(kod_zrodlowy == NULL){
- printf("Blad otwarcia pliku!\n");
- return -1;
- }
- //KOMENTARZ4
- odczytaj_kod_zrodlowy(kod_zrodlowy);
- if(fclose(kod_zrodlowy)){
- printf("Blad zamkniecia pliku!\n");
- return -1;
- }
- /*KOMENTARZ5*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement