Hej
Jeg har skrevet et lille C-program, der skriver en fils indhold ud på
skærmen sammen med liniernes numre, men der er bare en lille fejl i det,
ser det ud som (programmet kompilerer perfekt med "gcc -Wall ....").
Jeg får disse meddelser, når jeg kører programmet med:
"pointer pointer.c":
4766: symbol=fclose; lookup in file=pointer
4766: symbol=fclose; lookup in file=/lib/libc.so.6
4766: symbol=fclose; lookup in file=pointer
4766: symbol=fclose; lookup in file=/lib/libc.so.6
lookup 0x08048000 0x00000204 -> 0x40027000 0x00064d30 /1 fclose
4766: symbol=free; lookup in file=pointer
4766: symbol=free; lookup in file=/lib/libc.so.6
4766: symbol=free; lookup in file=/lib/ld-linux.so.2
Programmet er som følger:
--
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/types.h>
#include <string.h>
#include <errno.h>
int main(int argc, char *argv[])
{
char *buffer;
int line=0;
if (argc == 1) {
fprintf(stdout,"Usage: writeout <file> [lines]\n");
fprintf(stdout,"Type in a filename to continue: ");
/* this is not really being used for anything, so return 0; */
/* make a system call to cat as a emergeny */
return 0;
}
/* proceed, as if-loop ended with return statement */
FILE *fd;
fd = fopen(argv[1],"r");
if(!fd){
fprintf(stderr,"It seems there was an error opening the file!\nError
message returned: ");
printf("%s\n",strerror(errno)); /* print the variable assigned as the
laste rror msg in <errno.h> */
exit(1); /* end the program */
}
while(fgets(buffer,1024,fd) != NULL){ /* buffer contains newline
character, so no need to load that */
line++;
printf("%d\t: %s",line,buffer);
}
fclose(fd);
return 0;
}
--
Mange tak for hjælpen på forhånd!
mvh.
Mads
--
Mads Jensen -
http://www.ddfr.dk
I have not got a suspicious email!
Flon's Law:
There is not now, and never will be, a language in which it is
the least bit difficult to write bad programs.