LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 10-17-2007, 08:52 PM   #1
bliss89
LQ Newbie
 
Registered: Oct 2007
Posts: 2

Rep: Reputation: 0
Need help with parse error problem


Hey,
I writing a simple unix program, however, ever time I try to compile my program the same message pops up: "parse error before "printf." I can't figure out what I've done wrong.

Here is my program,

#include <stdio.h>
#include <math.h>
int main()
{
int k, b_k;
b_k =0

printf("\n\n");
printf("Part (a):");
printf("\n\n");
printf(" i b_k=k^3-1 ");
printf("\n____________________ ");
for(k=1;k<=20;k++){
b_k = (k)^3-1
printf(" %2d %6d", k, b_k);}
}

prg.c: In function `main':
prg.c:8: error: parse error before "printf"
prg.c:15: error: parse error before "printf"
 
Old 10-17-2007, 09:19 PM   #2
Hivemind
Member
 
Registered: Sep 2004
Posts: 273

Rep: Reputation: 30
Missing semicolon after
Code:
b_k =0
With an editor that supports automatic indentation like emacs, such things are easy to spot. Also, post code inside code tags next time.
 
Old 10-17-2007, 09:23 PM   #3
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
Quote:
b_k =0
missing semicolon
Quote:
b_k = (k)^3-1
missing semicolon
Quote:
printf(" i b_k=(k^3-1 ");
missing right parenthesis around k^3.

Beyond that, the expressions k=k^3-l and k=(k)^3-1 generate warnings. Put k^3 in parentheses and the warning go away.

End result:
Quote:
1 #include <stdio.h>
2 #include <math.h>
3 int main()
4 {
5 int k, b_k;
6 b_k =0;
7
8 printf("\n\n");
9 printf("Part (a):");
10 printf("\n\n");
11 printf(" i b_k=(k^3)-1 ");
12 printf("\n____________________ ");
13 for(k=1;k<=20;k++){
14 b_k = (k^3)-1;
15 printf(" %2d %6d", k, b_k);}
16 }
Only one warning left:
Quote:
prog.c: In function `main':
prog.c:16: warning: control reaches end of non-void function

Last edited by bigrigdriver; 10-17-2007 at 09:30 PM.
 
Old 10-17-2007, 09:53 PM   #4
bliss89
LQ Newbie
 
Registered: Oct 2007
Posts: 2

Original Poster
Rep: Reputation: 0
I completely missed that, now I feel a bit stupid. Thanks, i guess it's obvious that I'm new at programming. Also, when I executed the program I got something that was crazy. I'll see if I can fix it, if not I'll post it here. Again, thanks for the help.
 
  


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
Splint parse error problem when used pthread rajsun Programming 4 10-07-2010 01:27 AM
What's the meaning of "PHP Parse error: parse error, unexpected $ in..." frandalla Programming 23 03-04-2009 12:34 PM
need help with "Parse error: parse error, unexpected T_STRING" coffee245 Programming 2 01-29-2007 11:53 AM
in gcc compiler error: parse error before string constsnt cynthia_thomas Linux - Networking 1 10-20-2005 01:29 AM
Parse Error verbatim Programming 3 04-22-2005 09:16 AM

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

All times are GMT -5. The time now is 12:49 AM.

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