Hi!
I am having trouble opening a file and then reading its content and in the end displaying it. Here is the code:
Code:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
FILE *fp;
fp = fopen("/boot/grub/menu.lst", "r");
char *line;
line = malloc(128);
int i;
if(fp == NULL)
{
printf("Could not open the file!\n");
}else
{
printf("File opened for input");
while(!feof(fp))
{
fgets(line, 128, fp);
for(i = 0; i < 128; i++ )
printf("%c", line[i]);
}
}
fclose(fp);
return 0;
}
The output is a complete mess:
Quote:
itrd /boot/initrd.img-2.6.20-15-generic
=UUID=2b154dc2-73a3-4df2-817a-90e112bc04cd ro single
lash
title Ubuntu, memtest86+
6.20-15-generic
=UUID=2b154dc2-73a3-4df2-817a-90e112bc04cd ro single
lash
root (hd0,0)
memtest86+
6.20-15-generic
=UUID=2b154dc2-73a3-4df2-817a-90e112bc04cd ro single
lash
kernel /boot/memtest86+.bin
0-15-generic
=UUID=2b154dc2-73a3-4df2-817a-90e112bc04cd ro single
lash
quiet
/boot/memtest86+.bin
0-15-generic
=UUID=2b154dc2-73a3-4df2-817a-90e112bc04cd ro single
lash
|
And this is just a part of the output. As you can see, parts of the things are repeated. How could I prevent this? And what could go wrong?
Thanx:
Dan