int getline (char line[], int max)
^
You forgot a semicolon.
It should be:
int getline (char line[], int max);
문제
I copied paste the following code from "C Programming Language" page 69:
#include <stdio.h>
#define MAXLINE 1000 /* maximum input line length */
int getline (char line[], int max)
int strindex (char source[], char searchfor[]);
char pattern[] = "ould"; /* pattern to search for */
/* find all lines matching pattern */
int main()
{
char line[MAXLINE];
int found = 0;
while (getline(line, MAXLINE) > 0)
if (strindex(line, pattern) >= 0)
{
printf("%s", line);
found++;
}
return found;
}
/* getline: get line into s, return length */
int getline(char s[], int lim)
{
int c, i;
i = 0;
while ( (--lim > 0) && (c=getchar() != EOF) && (c != '\n'))
s[i++] = c;
if (c == '\n')
s[i++] = c;
s[i] = '\0';
return i;
}
/* strindex: return index of t in s, -1 if none */
int strindex(char s[], char t[])
{
int i, j, k;
for (i = 0; s[i] != '\0'; i++)
{
for (j=i, k=0; t[k]!='\0' && s[j]==t[k]; j++, k++);
if (k > 0 && t[k] == '\0')
return i;
}
return -1;
}
I prepared this simple make file named "makefile"
mypage69: page69.o
gcc -g -ansi -Wall page69.o -o mypage69
page69.o: page69.c
gcc -c -ansi -Wall page69.c -o page69.o
However, when I enter the "make" command on linux shell:
VirtualBox:~/Desktop/Exercises/Book/mypage69$ make
gcc -c -ansi -Wall page69.c -o page69.o
page69.c: In function ‘getline’:
page69.c:8:1: error: parameter ‘pattern’ is initialized
page69.c:12:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
page69.c:30:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
page69.c:47:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
page69.c:5:5: error: old-style parameter declarations in prototyped function definition
page69.c:60:1: error: expected ‘{’ at end of input
page69.c:60:1: warning: control reaches end of non-void function [-Wreturn-type]
make: *** [page69.o] Error 1
VirtualBox:~/Desktop/Exercises/Book/mypage69$
Can someone please help with this? There is only 1 c file here.
Thanks.
해결책
int getline (char line[], int max)
^
You forgot a semicolon.
It should be:
int getline (char line[], int max);
다른 팁
And you've probably an extra\unwanted semicolon on the end of for (j=i, k=0; t[k]!='\0' && s[j]==t[k]; j++, k++);