ubaka
01-17-2003, 07:11 AM
yo, here's my version of cat. it's very simple and does'nt take in any options or switches.
/* a cat-like program without options*/
#include <stdio.h>
#include <errno.h>
main(int argc, char *argv[])
{
FILE *fpt;
int i;
if (argc > 1) {
for (i=2; i<=argc;i++)
{
if ((fpt = fopen(argv[i-1], "r")) == NULL)
{
perror(argv[i-1]);
continue;
}
else
while (!feof(fpt))
putchar(getc(fpt));
printf("\n");
fclose(fpt);
}
}
else
fprintf(stderr, "usage: spit [filename]...\n");
return(0);
}
the problem here is after i run the executable, i get a funny looking character at the end of each file. can anybody help me debug?
/* a cat-like program without options*/
#include <stdio.h>
#include <errno.h>
main(int argc, char *argv[])
{
FILE *fpt;
int i;
if (argc > 1) {
for (i=2; i<=argc;i++)
{
if ((fpt = fopen(argv[i-1], "r")) == NULL)
{
perror(argv[i-1]);
continue;
}
else
while (!feof(fpt))
putchar(getc(fpt));
printf("\n");
fclose(fpt);
}
}
else
fprintf(stderr, "usage: spit [filename]...\n");
return(0);
}
the problem here is after i run the executable, i get a funny looking character at the end of each file. can anybody help me debug?