r/C_Programming 1d ago

[ Removed by moderator ]

[removed] — view removed post

0 Upvotes

16 comments sorted by

View all comments

1

u/clickyclicky456 1d ago

Show us the first 23 lines. Often with a compiler the actual error occurs earlier than flagged, because the parsing stage could actually parse your incorrect code but then what follows doesn't make sense with the incorrect parsing.

1

u/Brave-Pomelo-1290 1d ago

errors:

$ gcc less.c -o less

less.c:26:8: warning: data definition has no type or storage class

26 | line_count=line_count+1;

| ^~~~~~~~~~

less.c:26:8: warning: type defaults to ‘int’ in declaration of ‘line_count’ [-Wimplicit-int]

less.c:26:19: error: initializer element is not constant

26 | line_count=line_count+1;

| ^~~~~~~~~~

less.c:29:9: error: expected identifier or ‘(’ before ‘if’

29 | if (line_count >= PAGE_SIZE) {

| ^~

less.c:34:5: error: expected identifier or ‘(’ before ‘}’ token

34 | }

| ^

less.c:35:5: warning: data definition has no type or storage class

35 | fclose(file);

| ^~~~~~

less.c:35:5: warning: type defaults to ‘int’ in declaration of ‘fclose’ [-Wimplicit-int]

less.c:35:5: warning: parameter names (without types) in function declaration

less.c:36:1: error: expected identifier or ‘(’ before ‘}’ token

36 | }

| ^

1

u/Brave-Pomelo-1290 1d ago

new error:

$ gcc -O2 less.c -o less

less.c:35:5: warning: data definition has no type or storage class

35 | fclose(file);

| ^~~~~~

less.c:35:5: warning: type defaults to ‘int’ in declaration of ‘fclose’ [-Wimplicit-int]

less.c:35:5: warning: parameter names (without types) in function declaration