Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
09-18-2005, 05:16 PM
|
#1
|
|
Senior Member
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: LFS-Version SVN-20091202, Arch 2009.08
Posts: 1,467
Rep:
|
C source file Parse error before 38
Code:
#include<stdio.h>
#include<stdlib.h>
#define SIZE 100
int prog_enterd(int *,int);
int main()
{
int memory[SIZE]; //simulated memory
int mess;
int acc = 0;
int intructcounter;
int operationcode,operand;
int instruction;
int loop;
//print welcome message first
printf("\n\n");
printf("***Welcome to Simcom!***\n***Please enter your program one
instruction word at a time**\n***I will type the location number and a
question mark***\n***You then type the word for that
location***\n***Type the sentinal -99999 to stop entering your
program***\n");
mess = prog_enterd(memory,SIZE);
if ( mess == 0)
{
printf("You have run out of lines to enter programs or you are at the
end of memory\n");
exit (0);
}
else
{ printf("Great Program loading compleated\n");
}
printf("Program execution begins\n");
for (intructcounter =0; intructcounter != 43 && intructcounter
< 99 intructcounter++)
{
instruction = memory[intructcounter];
operationcode = instruction / 100;
operand = instruction % 100;
switch (operationcode)
{
case 10: scanf("%d", &memory[operand]); //read
break;
case 20: acc = memory[operand]; //load
break;
case 30: acc += memory[operand]; //add
break;
case 43: printf("Simcom exectution terminated\n"); //HALT
break;
case 11: printf("%d\n",memory[operand]; //write
break;
case 21: memory[operand] = acc; //store
break;
case 31: acc -= memory[operand]; //subtract
break;
case 32: acc /= memory[operand]; //devide
break;
case 33: acc *= memory[operand]; //multiply
break;
case 40: intructcounter = operand;
break;
case 41: if (acc < 0) intructcounter = operand;
break;
case 42: if (acc == 0) intructcounter = operand;
break;
}
}
printf("Program execution compleate\n");
printf("Memory dump information");
for (loop = 0; loop <= mess; loop++)
printf("%02d %04d%c",loop,memory[loop],(loop % 4 == 0) ? '/n' : ' ');
return 0;
}
int prog_enterd(int *mem, int size)
{
int count = 0;
do
{
printf("%02d ? ",count);
scanf("%d",&mem[count]);
printf("\n");
if (mem[count] == -99999)
return count - 1;
count++;
}
while (count < size);
return 0;
}
strange issue here it says i have a parse error before line 38 ((its in blue))
but i dont see it do any of you see it?
Last edited by exvor; 09-18-2005 at 05:18 PM.
|
|
|
|
09-18-2005, 05:24 PM
|
#2
|
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 42,832
|
well on line 38 you are missing a ; between 99 and intructcounter++
|
|
|
|
09-18-2005, 05:27 PM
|
#3
|
|
Senior Member
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: LFS-Version SVN-20091202, Arch 2009.08
Posts: 1,467
Original Poster
Rep:
|
Woops let me check source to make sure thats not in the real source
|
|
|
|
09-18-2005, 05:51 PM
|
#4
|
|
Senior Member
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86; Gentoo PPC; Gentoo Sparc64; FreeBSD; OS X; Solaris
Posts: 3,731
Rep:
|
Also:
Code:
printf("%02d %04d%c",loop,memory[loop],(loop % 4 == 0) ? '/n' : ' ');
should be:
Code:
printf("%02d %04d%c",loop,memory[loop],(loop % 4 == 0) ? '\n' : ' ');
With acid's change and mine, the proggy is compiling for me...
|
|
|
|
09-18-2005, 05:55 PM
|
#5
|
|
Senior Member
Registered: Jan 2003
Posts: 2,786
|
There's one more, but it's only a warning:
Code:
for (loop = 0; loop <= mess; loop++)
printf("%02d %04d%c",loop,memory[loop],(loop % 4 == 0) ? '/n' : ' ');
That's a multi-character, character constant. I assume you intended '\n'
|
|
|
|
09-19-2005, 02:10 PM
|
#6
|
|
Senior Member
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: LFS-Version SVN-20091202, Arch 2009.08
Posts: 1,467
Original Poster
Rep:
|
Yea I made both changes and now it compiles ok just doesent work as intended.
for some reason my transfer of control doesnt go where intened and the loop doesent stop looping
tho these are issues that i need to solve thanks everyone
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 06:13 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|