Wednesday, 2 October 2013

Can't get ANSI C code to compile with gcc

Can't get ANSI C code to compile with gcc

I got the following code from "The C Programming Language" written by
Brian Kernighan and Dennis Ritchie. However, it won't compile with gcc:
#include <stdio.h>
#include <string.h>
#define MAXLINE 1000
int getline(char *line, int max);
{
char line[MAXLINE];
int found = 0;
if (argc != 2)
printf("Usage: find pattern\n");
else
while (getline(line, MAXLINE) > 0)
if (strstr(line, argv[1]) != NULL) {
printf("%s", line);
found++;
}
return found;
}
All I get is: error: expected identifier or '(' before '{'.
What am I doing wrong?

No comments:

Post a Comment