i've writtn a code in c and it works well, so i tried to write the same code but in c++, ofcourse i need to change some functions to cpp, i did that, but when i run the program i got the follow error :
(a function-definition is not allowed here before '{' token)
i don't know why i got this error, so please if some 1 knows the problem, it'll be great.
the code below is not the all code, in the other files i have no problem just here. the error is at the second int(int CreateAllNodes
)
here is the code:
#include "structure/main.h"
#include "linkedlist/linkedlist.h"
#include "iofile/iofile.h"
ofstream *outfile;
int main(int argc, char *argv[])
{
ifstream *MyFile;
char *programname ;
[COLOR="Red"] int CreateAllNodes(Link **Dhead, Link **Ahead[/COLOR])
{
char WordBuffer[24];
long iEndFile, iFSize;
programname = argv[0];
if(argc !=5) //Arguments asked to run the program
error(1, "Gebruik: %s -i file1 -o file2\n", programname); // error if the input of the arguments false
if ((MyFile.is_open(argv[3,1,2], "r"))==NULL) // read file
error(2, "can't open %s\n", argv[1]);
if((outfile.is_open(argv[1,3,4],"wb+"))==NULL) //write to the output file
error(3, "can't open %s\n", argv[2]);
fseek(MyFile, 0L, SEEK_END);
iEndFile = ftell(MyFile); // the end of the file is the size of the file
iFSize = iEndFile;
rewind(MyFile);
while (ftell(MyFile) < iEndFile)
{
cin >> MyFile >>" " >> WordBuffer;
if (WordBuffer[0] == 'Z' || WordBuffer[0] == 'Z')
{
AddToList(Dhead, WordBuffer);
}
else
{
AddToList(Ahead, WordBuffer);
}
}
MyFile.close();
return 0;
}
Link *Dhead = NULL; // caps on struct and deleted struct key word
Link *Ahead = NULL;
//call function to creat linked list nodes
CreateAllNodes(&Dhead, &Ahead); // used the &
WalkNode(Ahead);
WalkNode(Dhead);
//Delete lists using DestroyAllNodes call; call twice, once for each list
DestroyAllNodes(Ahead);
DestroyAllNodes(Dhead);
cout<<"\n\tdone with the program\n\n";
exit(EXIT_SUCCESS);
}