This is the error I have been receiving when trying to compile my code:
blade71(45)% gcc -o trim trim.c
Undefined first referenced
symbol in file
getline /var/tmp//ccYdyoM3.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
My source is only a rough draft (Done in roughly 20 minutes). I have not yet began to break up the code into functions although I plan on line counting, whitespace counting, and trimming the whitespace all in separate functions. The problem is from K&R Programming C. The program is supposed to remove all excess whitespace from a program so when you do an octal dump there are no excess whitespace characters. Please don't tell me to use a library outside of stdio.h or how to do my program unless you see something dramatically wrong. (aside from my lack of functions and java like syntax)
#include <stdio.h>
/* This program will remove all trailing white space from an input file.
Using a loop containing several if statements to check for the ASCII
value of any white space generating characters; the program will
individually access each character until it reaches the EOF. */
main()
{
int c, newline, line, bytes_read;
int trim_count;
int nbytes = 100;
char *my_string;
my_string = (char *) malloc (nbytes + 1);
bytes_read = getline (&my_string, nbytes, stdin);
while ((c = getchar())!= EOF)
{
if (c == '\n' || c == ' ' || c == '\t')
{
newline++;
}
}
while (bytes_read !=0)
{
line++;
}
trim_count = line - newline;
while ((c = getchar())!= EOF)
{
if (c == '\n' || c == ' ' || c == '\t')
{
trim_count--;
putchar(c);
}
else if (trim_count <= 0)
{
continue; /* Had to be used because */
} /* of getchar's 1 argument */
else
{
putchar(c);
continue;
}
}
}