gcc is not pointing out WHERE my problem is

GCC is giving me these error messages, that are not pointing out exactly where my error is occuring in my code.
when I try to compile the code, this is what I get:

[code]
/home/user123/programs/source/deleteme.c: In function `check_subdir':
/home/user123/programs/source/deleteme.c:11: parse error at end of input
[/code]

The error in deleteme.c, line 11, is at the bottom outside of the main() body. The problem that I have
deduced, is that it's happening in check_subdir in wotfparm.h and thats becuase I compiled my program fine
before I added check_subdir() to wotfparm.h. Note, that the code listing Im giving you is a excerpt out of a bigger listing that
uses with a several names that have been changed to keep it simple and straight forward. It would still output the same error messages. I have looked up and down my
code (file wotfparm.h) to try and find what it is. Unless it's some typo that I cant see becuase of the long span between
the braces in the listing or it is something else thats giving me this problem - I dont see it. Thats where gcc is
not giving enough details of the error to me. Please, tell me, what is the problem is and why is it that gcc is not pointing it out me exactly
in the wotfparm.h file?

[code]
[black]

//file - deleteme.c

#include
#include "wotfparm.h"

int main(void)
{
//just a test to show that the problem is not here but with wotfparm.h that gcc is mispointing out
return 0;
}


[b] The following file is where I think where the bug is, but I can't find it. [/b]

[/black]

[red]

//file - wotfparm.h

//WOTF common values that need to be shared
#ifndef WOTFPARM
#define WOTFPARM

#include
#include

#include "filechck.h"

// Current Max. files for each instruction type section

#define WOTFA 137
#define WOTFB 51
#define WOTFC 73
#define WOTFD 54
#define WOTFE 17
#define WOTFF 2

//this value equals the number of WOTF sections above
#define GROUPS 6

//globals
char *fileprefix[6] = {"A_","B_","C_","D_","E_","F_"};
char *textwotfdir[6] = {"a/","b/","c/","d/","e/","f/"};
char *HTMLwotfdir[6] = {"A/","B/","C/","D/","E/","F/"};

//default paths, THAT I USE (Captain Crunch)
char *textwotfpath = { "/home/user123/textwotf/" };
char *HTMLwotfpath = { "/home/user123/HTMLwotf/" };

//file postfix
char *filepostfix[2] = {".txt", ".htm" };


short int check_subdir(char *, short int);

//wotfarea refers to either the source path = 0 or the destination path = 1
short int check_subdir(char *fpath, short int wotfarea)
{
short int flimits[GROUPS] = { WOTFA,WOTFB,WOTFC,WOTFD,WOTFE,WOTFF };
short int x,y,z,a, message_on = 0;//x

char tpath[120];

if (wotfarea != 0 || wotfarea != 1)
{
printf("
check_subdir: Neither source or destination locations are being checked
"); return 1;
}

for (x = 0;x < GROUPS; x++)
{
message_on = 0;//reset message flag
z = 0;//reset newline flag

for (y = 0;y < flimits[x]; x++)
{
if (wotfarea == 0)
{
sprintf(tpath,"%s%s%s%03d%s",fpath, textwotfdir[x], fileprefix[x], y, filepostfix[wotfarea]);


if ( (fname_check(tpath,0)) == 1)
{
if (message_on == 0)
{
printf("The following expected files are missing in the textwotf section:
");
message_on = 1;//message was used, do not show again
}

switch(x)
{
case 0:
{
if (z == 8) { printf("
"); z = 0;//reset z }
printf(" A_%03d.txt,",y); z++;
break;
}

case 1:
{
if (z == 8) { printf("
"); z = 0;//reset z }
printf(" B_%03d.txt,",y); z++;
break;
}

case 2:
{
if (z == 8) { printf("
"); z = 0;//reset z }
printf(" C_%03d.txt,",y); z++;
break;
}

case 3:
{
if (z == 8) { printf("
"); z = 0;//reset z }
printf(" D_%03d.txt,",y); z++;
break;
}

case 4:
{
if (z == 8) { printf("
"); z = 0;//reset z }
printf(" E_%03d.txt,",y); z++;
break;
}

case 5:
{
if (z == 8) { printf("
"); z = 0;//reset z }
printf(" F_%03d.txt,",y); z++;
break;
}

default:
{
printf(" check_subdir: unknown section not defined
",y);
break;
}
//end of switch block
}
//end of if block
}
//end of outer if block for wotfarea = 0
}

//HTMLwotf section

if (wotfarea == 1)
{
sprintf(tpath,"%s%s%s%03d%s",fpath, HTMLwotfdir[x], fileprefix[x], y, filepostfix[wotfarea]);

if ( (fname_check(tpath,0)) == 0)
{
if (message_on == 0)
{
printf("The following files exist in the HTMLwotf section for over-writting:
");
message_on = 1;//message was used, do not show again
}

switch(x)
{
case 0:
{
if (z == 8) { printf("
"); z = 0;//reset z }
printf(" A_%03d.htm,",y); z++;
break;
}

case 1:
{
if (z == 8) { printf("
"); z = 0;//reset z }
printf(" B_%03d.htm,",y); z++;
break;
}

case 2:
{
if (z == 8) { printf("
"); z = 0;//reset z }
printf(" C_%03d.htm,",y); z++;
break;
}

case 3:
{
if (z == 8) { printf("
"); z = 0;//reset z }
printf(" D_%03d.htm,",y); z++;
break;
}

case 4:
{
if (z == 8) { printf("
"); z = 0;//reset z }
printf(" E_%03d.htm,",y); z++;
break;
}

case 5:
{
if (z == 8) { printf("
"); z = 0;//reset z }
printf(" F_%03d.htm,",y); z++;
break;
}

default:
{
printf(" check_subdir: unknown section not defined
",y);
break;
}
//end of switch block
}
//end of if block
}
//end of if block for wotfarea == 1
}

// initialize tpath string
for (a = 0;a < 120; a++) { tpath[a] = '';}
printf("
");//new line spacer

//for loop end for y
}

if (wotfarea == 1)
{
printf(" note: do not choose above in HTMLwotf section,
");
printf(" files to be overwritten if you do not want them to.
");
}


//outer for loop block end for groups
}

return 0;
}

#endif

[/red]

[b] I dont think the error lies in this following file, but I have included it since its included in wotfparm.h
in case its necessary to compile the program [/b]

[black]

//file - filechck.h

#ifndef FILECHCK_H
#define FILECHCK_H

#include

int fname_check(char *,unsigned int);

//-------------------------------------------------------------------
/*
fname_check() is the same as file_check(), but provides its own
FILE pointer instead of one being passed.

*fname, passes the pointer to a char array consisting of the filename
b, tells to show messages or not

if _file_check's argument - unsigned int b is :
1... then messages will be displayed,
0... or other values (except 1) turn off messages

_file_check's argument - char *
... is used for passing in a file name.

if _file_check's return value is:
1... then the file was not found
0... then the file was found
(note : 1 is also the default value if both condition tests are false)
*/

int fname_check(char *fname, unsigned int b)
{
FILE *fs;//provides a file path

// check for file existence
if (b == 1) printf(" Checking for %s....",fname);

if ((fs = fopen(fname, "rb")) == NULL)
{
if (b == 1) printf("not found..
");
return 1;// failure
}

if ((fs = fopen(fname, "rb")) != NULL)
{
if (b == 1) printf("found..
");
fclose(fs);
return 0;// success
}
return -1;//default value to return, if both tests fail
}


#endif

[/black]
[/code]

Comments

  • [b][red]This message was edited by Captain Crunch at 2005-8-10 19:24:32[/red][/b][hr]
    I found one nutral bug, but has no effect on the change of the compiling. I deleted the y from the printf() statement in both defaults in my switch and case.

    : [code]
    : [red]
    :
    : //file - wotfparm.h
    ....
    : default:
    : {
    : printf(" check_subdir: unknown section not defined
    ",y);
    : break;
    }
    : [/red]

    : [/code]
    :


  • I feel like I am talking to myself....

    I solved my problem and found that I was commenting out
    each of the closing brackets of the if statments in each of
    the cases in my switch blocks. And the reason that it was
    benign to me is becuase I thought that, for example:

    [code]

    if (x == 1)
    {
    printf("hello world
    ");
    //do something
    }

    [/code]

    is equivalent to ...

    [code]

    if (x == 1) { printf("hello world
    ");//do something }

    [/code]

    They are not equivalent, so lesson learned of using comments (again).
    So this was a question that ended up as a C programming problem
    not specific to UNIX. Sorry.

    However, I still want to know why didn't gcc actually point out to me
    in its error output the problem in wotfparm.h instead of my
    program deleteme.c ?

    Thanks






Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion