Re: Design... the right way.
- From: mike.rosset+gnus@xxxxxxxxx
- Date: Thu, 26 Jun 2008 16:46:51 GMT
pete <pfiland@xxxxxxxxxxxxxx> writes:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define MAX_FIELDS 19
#define PATH_MAX 10
enum pkg_vars {
pkgname,
pkgver
};
int main(void)
/*
** non prototype declarations
** is an obsolescent feature of the language
*/
{
int lines = 0;
char package[MAX_FIELDS][PATH_MAX];
/*
** A two dimensional array of char
*/
FILE *input = fopen("./test.sh", "r");
char line[PATH_MAX + 1];
if(input == NULL) {
perror("Error: running parser");
/*
** Nothing to fclose here
*/
exit(EXIT_FAILURE);
}
while(fgets(line, PATH_MAX, input)) {
line[strlen(line) - 1 ] = '\0';
if(lines < MAX_FIELDS) {
strcpy(package[lines], line);
}
lines++;
}
printf("name = %s\n", package[pkgname]);
printf("pkgver = %s\n", package[pkgver]);
printf("total = %d\n", lines);
/*
** A portable text stream, ends in a newline character.
*/
fclose(input);
return 0;
}
Pete, thanks for your response. Thank you for for your suggestions, all
of them make sense. I have a couple of questionsi. When you say "non
prototype declarations" you mean I should declare void as a parmater, it
not to be assumed.
Also I'm not sure what you mean by a portable stream should end in a
newline. Does that mean I should'nt remove it from line or I should copy
the line then remove it?
Mike Rosset
.
- Follow-Ups:
- Re: Design... the right way.
- From: pete
- Re: Design... the right way.
- From: Mike Wahler
- Re: Design... the right way.
- References:
- Design... the right way.
- From: mike . rosset+gnus
- Re: Design... the right way.
- From: Bartc
- Re: Design... the right way.
- From: mike . rosset+gnus
- Re: Design... the right way.
- From: pete
- Design... the right way.
- Prev by Date: Re: types, variable names and fields
- Next by Date: Re: How to learn C ?
- Previous by thread: Re: Design... the right way.
- Next by thread: Re: Design... the right way.
- Index(es):
Relevant Pages
|