visual c++: problems with pointers

D

Dark Knight

Hello,

I am trying to create a linklist program and I am running into a problem
with this line:

llrecord linklist::find(char ctemp[])

I get three compile errors:

error C2143: syntax error: missing ';' before 'tag::id'
error C2501: 'llrecord':missing storage-class or type specifiers
fatal error C1004: unexpected end of file found

all three are on that line in my linklist.cpp file

thanks in advance

Stephen

now the files

three files are involved assembly.cpp, linklist.cpp, and linklist.h

assembly.cpp:
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
#include <stdio.h>
#include <string.h>

// $C000 = 46152

int main()
{
ifstream infile("temp.txt");


return 0;
}


linklist.cpp
#include "linklist.h"
#include <stdio.h>
#include <string.h>


linklist::linklist()
{
char ctemp[5]={"zzzz"};
head=new llrecord;
strcpy(head->opcode, ctemp);
head->next=NULL;
}

linklist::~linklist()
{

}

void linklist::insert(llrecord x)
{
llrecord *llcurrent, *previous, *present;

llcurrent=first;
while(strcmp(x.opcode, llcurrent->opcode)>0)
{
previous=llcurrent;
llcurrent=llcurrent->next;
}
present=new llrecord;
strcpy(present->opcode, x.opcode);
strcpy(present->instruction, x.instruction);
present->numBytes=x.numBytes;
present->next=llcurrent;
if(llcurrent==first)
first=present;
else
previous->next=present;
return;
}

llrecord linklist::find(char ctemp[])
{
llrecord temp;

return temp;
}

bool linklist::eols(llrecord *)
{

}




linklist.h

#ifndef linklist_h
#define linklist_h

class linklist
{
public:

struct llrecord
{
char opcode[5];
int numBytes;
char instruction[10];
llrecord *next;
};

linklist();
~linklist();
void insert(llrecord);
llrecord find(char[]);
bool eols(llrecord *);

private:

llrecord *first;
llrecord *head;

};

#endif
 
M

Moonlit

Hi,


Dark Knight said:
Hello,

I am trying to create a linklist program and I am running into a problem
with this line:
First all, creating a linked list is real easy like this.

#include <list>
using namespace std;
list<llrecord> LinkedList;

Thats, it!
llrecord linklist::find(char ctemp[])


You should use it as follows, since llrecord is in the linklist scope:

linklist::llrecord linklist::find( char ctemp[] )

or way better:

linklist::llrecord linklist::find( const string& ctemp )

First try this maybe it solves the other errors too. (I didn;t scrutinize
the code).

Regards, Ron AF Greve.

I get three compile errors:

error C2143: syntax error: missing ';' before 'tag::id'
error C2501: 'llrecord':missing storage-class or type specifiers
fatal error C1004: unexpected end of file found

all three are on that line in my linklist.cpp file

thanks in advance

Stephen

now the files

three files are involved assembly.cpp, linklist.cpp, and linklist.h

assembly.cpp:
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
#include <stdio.h>
#include <string.h>

// $C000 = 46152

int main()
{
ifstream infile("temp.txt");


return 0;
}


linklist.cpp
#include "linklist.h"
#include <stdio.h>
#include <string.h>


linklist::linklist()
{
char ctemp[5]={"zzzz"};
head=new llrecord;
strcpy(head->opcode, ctemp);
head->next=NULL;
}

linklist::~linklist()
{

}

void linklist::insert(llrecord x)
{
llrecord *llcurrent, *previous, *present;

llcurrent=first;
while(strcmp(x.opcode, llcurrent->opcode)>0)
{
previous=llcurrent;
llcurrent=llcurrent->next;
}
present=new llrecord;
strcpy(present->opcode, x.opcode);
strcpy(present->instruction, x.instruction);
present->numBytes=x.numBytes;
present->next=llcurrent;
if(llcurrent==first)
first=present;
else
previous->next=present;
return;
}

llrecord linklist::find(char ctemp[])
{
llrecord temp;

return temp;
}

bool linklist::eols(llrecord *)
{

}




linklist.h

#ifndef linklist_h
#define linklist_h

class linklist
{
public:

struct llrecord
{
char opcode[5];
int numBytes;
char instruction[10];
llrecord *next;
};

linklist();
~linklist();
void insert(llrecord);
llrecord find(char[]);
bool eols(llrecord *);

private:

llrecord *first;
llrecord *head;

};

#endif
 
R

Ron Natalie

Dark Knight said:
Hello,

I am trying to create a linklist program and I am running into a problem
with this line:

llrecord linklist::find(char ctemp[])

llrecord is not known at namespace (global) scope. It's a internal
type to linklist:
linklist::llrecord linklist::find(char* ctemp);
 
R

Ron Natalie

Dark Knight said:
Hello,

I am trying to create a linklist program and I am running into a problem
with this line:

llrecord linklist::find(char ctemp[])

I get three compile errors:

error C2143: syntax error: missing ';' before 'tag::id'
error C2501: 'llrecord':missing storage-class or type specifiers
fatal error C1004: unexpected end of file found

all three are on that line in my linklist.cpp file

thanks in advance

Stephen

now the files

three files are involved assembly.cpp, linklist.cpp, and linklist.h

assembly.cpp:
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
#include <stdio.h>
#include <string.h>

// $C000 = 46152

int main()
{
ifstream infile("temp.txt");


return 0;
}


linklist.cpp
#include "linklist.h"
#include <stdio.h>
#include <string.h>


linklist::linklist()
{
char ctemp[5]={"zzzz"};
head=new llrecord;
strcpy(head->opcode, ctemp);
head->next=NULL;
}

linklist::~linklist()
{

}

void linklist::insert(llrecord x)
{
llrecord *llcurrent, *previous, *present;

llcurrent=first;
while(strcmp(x.opcode, llcurrent->opcode)>0)
{
previous=llcurrent;
llcurrent=llcurrent->next;
}
present=new llrecord;
strcpy(present->opcode, x.opcode);
strcpy(present->instruction, x.instruction);
present->numBytes=x.numBytes;
present->next=llcurrent;
if(llcurrent==first)
first=present;
else
previous->next=present;
return;
}

llrecord linklist::find(char ctemp[])
{
llrecord temp;

return temp;
}

bool linklist::eols(llrecord *)
{

}




linklist.h

#ifndef linklist_h
#define linklist_h

class linklist
{
public:

struct llrecord
{
char opcode[5];
int numBytes;
char instruction[10];
llrecord *next;
};

linklist();
~linklist();
void insert(llrecord);
llrecord find(char[]);
bool eols(llrecord *);

private:

llrecord *first;
llrecord *head;

};

#endif
 
S

Stanley Yue

Dark Knight said:
Hello,

I am trying to create a linklist program and I am running into a problem
with this line:

llrecord linklist::find(char ctemp[])

I get three compile errors:

error C2143: syntax error: missing ';' before 'tag::id'
error C2501: 'llrecord':missing storage-class or type specifiers
fatal error C1004: unexpected end of file found

all three are on that line in my linklist.cpp file

thanks in advance

Stephen

now the files

three files are involved assembly.cpp, linklist.cpp, and linklist.h

assembly.cpp:
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
#include <stdio.h>
#include <string.h>

// $C000 = 46152

int main()
{
ifstream infile("temp.txt");


return 0;
}


linklist.cpp
#include "linklist.h"
#include <stdio.h>
#include <string.h>


linklist::linklist()
{
char ctemp[5]={"zzzz"};
head=new llrecord;
strcpy(head->opcode, ctemp);
head->next=NULL;
}

linklist::~linklist()
{

}

void linklist::insert(llrecord x)
{
llrecord *llcurrent, *previous, *present;

llcurrent=first;
while(strcmp(x.opcode, llcurrent->opcode)>0)
{
previous=llcurrent;
llcurrent=llcurrent->next;
}
present=new llrecord;
strcpy(present->opcode, x.opcode);
strcpy(present->instruction, x.instruction);
present->numBytes=x.numBytes;
present->next=llcurrent;
if(llcurrent==first)
first=present;
else
previous->next=present;
return;
}


llrecord linklist::find(char ctemp[])
**** you should write this sentence like this:

linklist::llrecord linklist::find(char ctemp[])

The reason is llrecord is a member struct of linklist ,so you must
add "linklist::" before it. it will tell compiler the struct llrecord
belongs to linklist.

{
llrecord temp;

****local variable 'temp' used without having been **initialized**
return temp;
}

bool linklist::eols(llrecord *)
{
****here: you must give it a return
}




linklist.h

#ifndef linklist_h
#define linklist_h

class linklist
{
public:

struct llrecord
{
char opcode[5];
int numBytes;
char instruction[10];
llrecord *next;
};

linklist();
~linklist();
void insert(llrecord);
llrecord find(char[]);
bool eols(llrecord *);

private:

llrecord *first;
llrecord *head;

};

#endif
 
S

Samuel Barber

Dark Knight said:
assembly.cpp:
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
#include <stdio.h>
#include <string.h>

// $C000 = 46152

There's your problem. Try this:
// $C000 = 49152

Sam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top