473,320 Members | 2,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Maybe a stupid question about short ev.

Hi everybody,

I'm new to C and I have some example that won't compile with gcc

Expand|Select|Wrap|Line Numbers
  1. /* auf0202.c */
  2.  
  3. #include <stdio.h>
  4.  
  5. int main(void)
  6. {
  7.     int i, einsen, zahl;
  8.  
  9.     printf("Pls enter a number:\n");
  10.     scanf("%d\n", &zahl);
  11.     zahl >= 0 ?
  12.         printf("positiv\n");
  13.         printf("negativ\n");
  14.     zahl % 2 ?
  15.         printf("Ungrade\n");
  16.         printf("Gerage\n");
  17.     einsen = 0;
  18.     i = 8 * sizeof(int);
  19.     while (i--)
  20.     {
  21.         einsen += zahl & 1;
  22.         zahl >>= 1;
  23.     }
  24.     printf("Anzahl len: %d\n", einsen);
  25.  
  26.     return 0;
  27. }
Failure: expect : before ; token

... what is my fault?
Sep 24 '07 #1
2 1434
Savage
1,764 Expert 1GB
Hi everybody,

I'm new to C and I have some example that won't compile with gcc

Expand|Select|Wrap|Line Numbers
  1. /* auf0202.c */
  2.  
  3. #include <stdio.h>
  4.  
  5. int main(void)
  6. {
  7.     int i, einsen, zahl;
  8.  
  9.     printf("Pls enter a number:\n");
  10.     scanf("%d\n", &zahl);
  11.     zahl >= 0 ?
  12.         printf("positiv\n");
  13.         printf("negativ\n");
  14.     zahl % 2 ?
  15.         printf("Ungrade\n");
  16.         printf("Gerage\n");
  17.     einsen = 0;
  18.     i = 8 * sizeof(int);
  19.     while (i--)
  20.     {
  21.         einsen += zahl & 1;
  22.         zahl >>= 1;
  23.     }
  24.     printf("Anzahl len: %d\n", einsen);
  25.  
  26.     return 0;
  27. }
Failure: expect : before ; token

... what is my fault?
Your fault is incorrect use of trinary operator ?.

It has syntax:

(codition)?if true:if not true;

Savage
Sep 24 '07 #2
Your fault is incorrect use of trinary operator ?.

It has syntax:

(codition)?if true:if not true;

Savage
Yes it works, thanks a lot.
I came from ruby, ... still hard for me to get with all the :;{... things :)
Sep 24 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: sebb | last post by:
I'm kind of newbie to programming, but I thought of something and I want some opinions on that. It's about a new instruction block to do some cycles. I thought about that because it's not very...
4
by: Jane Withnolastname | last post by:
I am trying to re-work an old site by replacing the html with css. On the main page, I have a logo image which I needed centred on the initial screen. I found the solution here:...
5
by: raz | last post by:
Greetings all. I apologize for what is almost certainly a stupid question, but I can't figure this out, and have no more time for head bashing... The short version: what is the appropriate...
16
by: Justin Hoffman | last post by:
This is a question concerning query optimisation. Sorry if it's a bit long, but thanks to anyone who has the patience to help - This is my first post here... If I have two tables:...
36
by: Hoopster | last post by:
Hello, I know nothing about C++ but want to get started. Is there any good free C++ program that I can try to see if I like programming? I also need a good free compiler. I don't want to...
30
by: Skybuck Flying | last post by:
I was just trying to figure out how some C code worked... I needed to make a loop to test all possible values for a 16 bit word. Surprise Surprise... C sucks at it... once again :D lol... C is...
2
by: Lampa Dario | last post by:
Hi, where is this stupid error in this program? When I execute it, i receive a segmentation fault error. #include <stdio.h> int main(int argc, char *argv, char *env) { int i=0; int l=0; int...
8
by: rollasoc | last post by:
Hi, Made me laugh so I though I'd share this. short i = 32; short j = 1; short k = i + j; gives an error Cannot implicitly convert type 'int' to 'short'
10
by: Steven Nagy | last post by:
private void Test(short i, short j) { short k = i + j; } What the hell is wrong with this code? "Can not implicitly convert type int to short" is the compile error. ASP.NET 1.1 C# Thanks
24
by: dmitrey | last post by:
Hi all, I looked to the PEPs & didn't find a proposition to remove brackets & commas for to make Python func call syntax caml- or tcl- like: instead of result = myfun(param1, myfun2(param5,...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.