LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 09-18-2005, 05:16 PM   #1
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: Gentoo, LFS, Debian,Ubuntu
Posts: 1,537

Rep: Reputation: 87
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.
 
Old 09-18-2005, 05:24 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
well on line 38 you are missing a ; between 99 and intructcounter++
 
Old 09-18-2005, 05:27 PM   #3
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: Gentoo, LFS, Debian,Ubuntu
Posts: 1,537

Original Poster
Rep: Reputation: 87
Woops let me check source to make sure thats not in the real source
 
Old 09-18-2005, 05:51 PM   #4
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
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...
 
Old 09-18-2005, 05:55 PM   #5
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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'
 
Old 09-19-2005, 02:10 PM   #6
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: Gentoo, LFS, Debian,Ubuntu
Posts: 1,537

Original Poster
Rep: Reputation: 87
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Parse Error, but why? Mistro116@yahoo.com Programming 2 11-13-2005 02:38 PM
in gcc compiler error: parse error before string constsnt cynthia_thomas Linux - Networking 1 10-20-2005 01:29 AM
ENTRY in .S file results in parse error Dagda99 Programming 9 08-03-2004 04:59 PM
What is parse error ? edhan Linux - Newbie 64 09-17-2003 06:49 AM
Parse error returned when compiling a source file with Kdevelop spilios Programming 1 09-09-2003 06:00 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration