Badly places ()'s on C


 
Thread Tools Search this Thread
Top Forums Programming Badly places ()'s on C
# 1  
Old 09-24-2013
Badly places ()'s on C

I dont know why this Linux would give me badly placed () error all the time for this;


Code:
#include <stdio.h>
int main() 
{
	register int num=0 ;
	while ((num < 5))
		++num;
	  	printf("Pass %d \n", num) ; 
	return 0 ; 
}



can anyone help me please?
# 2  
Old 09-24-2013
Are you sure your error is in that bit of code you submitted?
Can you show us the error message you get ?
This User Gave Thanks to vbe For This Post:
# 3  
Old 09-24-2013
Quote:
Originally Posted by sizzler786
I dont know why this Linux would give me badly placed () error all the time for this;
It doesn't.
# 4  
Old 09-24-2013
Quote:
Originally Posted by sizzler786
I dont know why this Linux would give me badly placed () error all the time for this;


Code:
#include <stdio.h>
int main() 
{
	register int num=0 ;
	while ((num < 5)) {
		++num;
	  	printf("Pass %d \n", num) ; 
	}
        return 0 ; 
}



can anyone help me please?
It is always MUCH easier to help you solve problems like this if you show us the error message(s) you get when you post a question like this.

As a very wild guess, I'd say that you're trying to execute C code with a shell.

Assuming that the above code is stored in a file with a name ending with ".c" (such as "example.c"), the following should compile your code (although it probably won't do what you expect it to):
Code:
gcc -o example example.c

and then you could run the compiled program with:
Code:
./example

and the output produced would be something like:
Code:
Pass 5

If the output you wanted was something like:
Code:
Pass 1 
Pass 2
Pass 3
Pass 4

you could get that by adding the braces shown in red above.
These 2 Users Gave Thanks to Don Cragun For This Post:
# 5  
Old 09-26-2013
Yeah i think i was trying to execute it as a .c file whereas i compiled it as .o, nevermind, thankyou anyway Smilie

---------- Post updated at 01:14 PM ---------- Previous update was at 01:10 PM ----------

Code:
#include <stdio.h>
main()
{
int a = 128;
int b = 253;
int i;

for (i=7; i>=0; i--0);
	{
	 if (a & b => 128);
	 {printf("1");}
	 else
	 {printf("0");}
	}

a = a >> 1;

}


It won't work...


reg.c: In function 'main':
reg.c:8: error: expected ')' before numeric constant
reg.c:10: error: expected expression before '>' token
reg.c:12: error: expected expression before 'else'



thankyou
# 6  
Old 09-26-2013
There are some fairly elementary syntax errors in your code.
Code:
#include <stdio.h>
main()
{
int a = 128;
int b = 253;
int i;

for (i=7; i>=0; i--)
        {
         if (a & b >= 128)
         {printf("1");}
         else
         {printf("0");}
        }

a = a >> 1;

}

This User Gave Thanks to Scott For This Post:
# 7  
Old 09-26-2013
binq

Thank you.

I wrote that code to get a binary form of the value of variable 'b'.. But its only giving me 00000000. Wheres the logical error?



Sahil
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sum the fields with 6 decimal places - getting only 2 decimal places as output

I used the below script to Sum up a field in a file based on some unique values. But the problem is when it is summing up the units, it is truncating to 2 decimals and not 6 decimals as in the input file (Input file has the units with up to 6 Decimals – Sample data below, when the units in the 2... (4 Replies)
Discussion started by: brlsubbu
4 Replies

2. Shell Programming and Scripting

Badly placed ()'s

Edit - I don't know how to delete posts. The question I asked here ended up not being the question I should have asked as I didn't realise I needed to edit my script to comply with SGE. Hi, My script is: #!/bin/bash # Perform fastqc on files in a specified directory. for ((j=1;... (8 Replies)
Discussion started by: una1992
8 Replies

3. Shell Programming and Scripting

Badly Placed ()'s when trying to use csh

The terminal is bash. Whenever I try to execute csh just by itself it gives Badly Placed ()'s. Whenever I try to use csh with a script it also gives Badly Placed ()'s. My script is this, there is nothing wrong with it, since it used by other students in class as well. (I have also asked... (5 Replies)
Discussion started by: quantumizer
5 Replies

4. Shell Programming and Scripting

Another case of Badly placed parens.

The shell error message "Badly placed ()'s" can occur for a surprisingly simple oversight. If the script begins with a shell-invocation comment, but is missing the exclamation-point, it is simply a comment and not an invocation. If you attempt to execute it from a shell other than the shell you... (4 Replies)
Discussion started by: Dickster
4 Replies

5. Shell Programming and Scripting

badly placed ()'s

i'm trying to run the following program but i keep getting the message "badly placed ()'s" can u help? #include "modularity_mat.h" #include "../sparse_mlpl/sparse_matrix.h" adj_matrix_arr* allocate_mem_for_matrix_arr (int y) { /* Create the adj matrix and allocate memory */ ... (2 Replies)
Discussion started by: ronirosner
2 Replies

6. UNIX for Dummies Questions & Answers

Need Help Badly: Newbie Here

I have this file: NPANXX|BILLDATE|DIVCODE|COMID|RAO|LIKECODE|BOSS|SORD|STATECODE| 087001|BP01|H|SWBT| |041|IMR6|IMSR6|AR| 087002|BP03|H|SWBT| |042|IMR6|IMSR6|AR| 087003|BP05|H|SWBT| |043|IMR6|IMSR6|AR| .... these are the things that i HAve to do: Insert a new column named “TEST” All... (14 Replies)
Discussion started by: arkhei
14 Replies

7. Shell Programming and Scripting

Badly formed number.

I have the following script running every day numerous times a day and it works fine, but very occasionally I get the following error if: Badly formed number. Anyone know why? Here is the script that runs with the follow parms LCTMDBSE 100000 130000 160000 #!/bin/csh ... (0 Replies)
Discussion started by: Northerner
0 Replies

8. Shell Programming and Scripting

sed help needed badly

how can I delete one line above and below the matching pattern ? e.g I want to delete the line above and below the line with %CLI- in example below : $CHECKSUM $1$DGA1043:TSTST01.DBF;1 %CLI-E-OPENIN, error opening $1$DGA1043:TSTST01.DBF -RMS-E-FLK, file currently locked by another user ... (6 Replies)
Discussion started by: aliyesami
6 Replies

9. Shell Programming and Scripting

for:badly formed number

Hi, I am doing the following but it complains and says "for:badly formed number" does anyone know why? #!/bin/tcsh foreach(....) ............ set depth=64 set width=23 if ($depth==64) then echo "if" set addr_bits=5 else echo "else" endif echo "addr_bits:$addr_bits" echo... (3 Replies)
Discussion started by: ROOZ
3 Replies

10. Shell Programming and Scripting

Badly placed ()'s. - error

Hi, when I execute the below script, I am getting following error "Badly placed ()'s". can anyone please help me fix ---------------------------------------------------------- # Usage: ani -n -a -s -w -d # # # help_ani() To print help # help_ani() { echo "Usage: $0 -n -a -s -w -d"... (3 Replies)
Discussion started by: amitrajvarma
3 Replies
Login or Register to Ask a Question