Exercise_1-16.c:5: error: conflicting types for ‘getline’ /usr/include/stdio.h:651: note: previous declaration of ‘getline’ was here Exercise_1-16.c:15: error: conflicting types for ‘getline’ /usr/include/stdio.h:651: note: previous declaration of ‘getline’ was here
#include <stdio.h>
#define maxlength 1000
int getline(char line[]); // Forward declaration, but it's not working
int main() {
int c;
char string1[maxlength];
while ((c = getline(string1)) > 0) // Print the line
printf("%s", string1);
return 0;
}
int getline(char line[]) {
int c, i, j, linebreak1 = 0;
for (i = 0; (c = getchar()) != EOF && c != '\n'; ++i)
line[i] = c; // Write the characters to the string.
if (c == '\n') // So we know if we need a linebreak at the end
linebreak1 = 1;
j = i - 1;
for (j; (j > -1) &&( line[j] == '\n' || line[j] == '\t' || line[j] == ' ' || line[j] == EOF); --j) {
line[j] = '\0'; // Start from the end of the string and keep inserting the "end character" until
// we hit a non-space character. This makes it so we don't print spaces.
}
if (linebreak1 == 1 && line[0] != '\0') {
line[j + 1] = '\n'; // If the line isn't empty, and a linebreak is necessary, print a linebreak.
line[j + 2] = '\0'; // End of character.
}
else
line[j + 1] = '\0'; // There must be some reason as to why I wrote this, but I can't remember what it was.
return i;
}

New Topic/Question
Reply



MultiQuote




|