C programming, calling a function -
i new c , trying iteratively phone call line in stream , check see if contains search string or if null. cant figure out how create check, warning saying [warning] comparing between pointer , integer or [warning] assignment makes pointer integer without cast whenever seek , this. can help? thanks.
#include <stdio.h> #include <errno.h> #include <string.h> #include <stdlib.h> #include <unistd.h> int main(int argc, char *argv[]) { file *fpntr; char *file_pathname, *first_line; if (argc != 2) { fprintf(stderr, "usage: %s file\n", argv[0]); homecoming exit_failure; } file_pathname = argv[1]; if ((fpntr = fopen(file_pathname, "r")) == null ) { fprintf(stderr, "error opening file %s: %s\n", file_pathname, strerror(errno)); homecoming exit_failure; } else { grep_stream(); fclose(fpntr); } homecoming exit_success; } int grep_stream(file *fpntr, char *string, char *file_pathname) { //warning on next line while ((? = get_next_line(fpntr)) == null ) { perror("error reading line"); exit(exit_failure); } elseif() { printf("first line in : %s \n %s", file_pathname, string); } } char *get_next_line(file *fpntr) { char *buff = malloc(101); int pos = 0; int next; while ((next = fgetc(fpntr)) != '\n' && next != eof) { buff[pos++] = next; } buff[pos] = '\0'; if (buff != null ) { homecoming buff; } else homecoming null ; }
remember c code compiled top-to-bottom. function get_next_line
isn't declared time while
line read.
either move get_next_line
's definition before main
's, or forward-declare saying:
char *get_next_line(file *fpntr);
beforehand. reason you're getting warning instead of error undeclared functions assumed homecoming int
, no assumptions made parameters. is, have type int()
.
also, format code both sake , of answering questions (or working you.)
c
No comments:
Post a Comment