i like that function fgets() i see it is used a lot to read characters and input, i came across a getline() it was said that it can do the same, i wanted to implement this using the same idea mike and is not quite working, what can change about my code to correctly implement this idea, I tried getline by itself and i can use it to count characters. Can this be done ? I know fgets() works but i need to learn more since i am quite new at this.
Code:
#include <stdio.h>
#define MAXLINE 100
int main()
int getline (char s[], int maxline);
{
int i=0;
char line[MAXLINE];
getline(line, MAXLINE, stdin);
printf("the string %s has a hex character of: ", line);
while (line[i] != '\0')
{
printf("%3x", line[i]);
i++;
}
getchar();
}
int getline (char s[], int maxline)
{
int c, i;
for ( i=0; ( c=getchar() ) != EOF && c!='\n'; ++i)
s[i] = c;
if ( c =='\n') {
s[i] = c;
++i;
}
s[i] = '\0';
return i;
}
c:4 error: declaration for parameter "getline" but no such parameter
c:9 error: too many arguments to function