23/12/09 10:22
gighen991
Salve a tutti.. è due giorni che cerco di capire come mai mi si visualizzino questi errori nel codice del programma. Il mio sistema operativo è ubuntu 9.10 e quando compilo il programma mi da questi errori
il codice del programma è il seguente
Grazie anticipatamente a tutti per l'aiuto
hackerj@hackerj-laptop:~$ gcc -o notesearch notesearch.c notesearch.c:78: error: expected ‘)’ before ‘*’ token notesearch.c:79: error: expected declaration specifiers or ‘...’ before string constant notesearch.c:79: error: expected declaration specifiers or ‘...’ before ‘length’ notesearch.c:79: error: expected declaration specifiers or ‘...’ before ‘note_uid’ notesearch.c:79: warning: data definition has no type or storage class notesearch.c:79: error: conflicting types for ‘printf’ notesearch.c:79: note: a parameter list with an ellipsis can’t match an empty parameter name list declaration notesearch.c:80: error: expected identifier or ‘(’ before ‘return’ notesearch.c:81: error: expected identifier or ‘(’ before ‘}’ token
il codice del programma è il seguente
#include<stdio.h> #include<string.h> #include<fcntl.h> #include<sys/stat.h> #include "hacking.h" #define FILENAME "/var/notes" int print_notes(int, int, char *); int find_user_note(int, int); int search_note(char *, char *); void fatal(char *); int main(int argc, char *argv[]) { int userid, printing=1, fd; char searchstring[100]; if(argc > 1) // se esiste un arg, strcpy(searchstring, argv[1]); // quella è la stringa di ricerca; else searchstring[0] = 0; // la stringa di ricerca è vuota. userid = getuid(); fd = open(FILENAME, O_RDONLY); // apre il file in sola lettura if( fd == -1) fatal("in main() while opening file for reading"); while(printing) printing = print_notes(fd, userid, searchstring); printf("-------[end of note data ]--------\n"); close(fd); } // Stampa le note per un determinato id utentecorrispondenti a una // Stringa opzionale // Restituisce 0 alla fine del file o 1 se ci sono altre note; int print_notes(int fd, int uid, char *searchstring){ int note_length; char byte=0; char note_buffer[100]; note_length = find_user_note(fd, uid); if(note_length == -1) return 0; read(fd, note_buffer, note_length); note_buffer[note_length] = 0; if(search_note(note_buffer, searchstring)) printf("%s", note_buffer); return 1; } // Trova la nota successiva per un determinato id utente; // Restituisce -1 alla fine del file; // Altrimenti restituisce la lunghezza del file int find_user_note(int fd, int user_uid) { int note_uid = -1; unsigned char byte; int length; while(note_uid != user_uid) { if(read(fd, ¬e_uid, 4) != 4) return -1; if(read(fd, &byte, 1) != 1) return -1; byte = length = 0; while(byte != '\n') if(read(fd, &byte, 1) != 1) return -1; length++; } } lseek(fd, length * -1, SEEK_CUR); // Riporta la lettura del file indietro di length byte. printf("[DEBUG] found a %d byte note for user id %d\n", length, note_uid); return length; } // Ricerca di nota in base a una parola chiave, 1 in caso di successo e 0 in caso contrario int search_note(char *note, char *keyword) { int i, keyword_length, match=0; keyword_length=strlen(keyword); if(keyword_length == 0) return 1; for(i=0; i< strlen(note); i++) { if(note[i] == keyword[match]) match++; else { if(note[i] == keyword[0]) match = 1; else match = 0; } if(match == keyword_length) return 1; } return 0; }
Grazie anticipatamente a tutti per l'aiuto
aaa