10 Replies - 922 Views - Last Post: 11 June 2009 - 04:48 AM Rate Topic: -----

#1 tashe   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 107
  • Joined: 10-March 09

C conditional

Posted 08 June 2009 - 03:04 PM

H i have this C code, that I found in a solved example:

if( pos > 0 ) L[i] <?= L[i-1];


and it raises this error:

syntax error before '?' token

I know that ?: is used like if-then-else statement. I did some search on google but all I found was about ?: . Does somebody know what is the intention of this operator and how can I repair this error?
thanks

Is This A Good Question/Topic? 0
  • +

Replies To: C conditional

#2 erik.price   User is offline

  • D.I.C Lover
  • member icon

Reputation: 486
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Re: C conditional

Posted 08 June 2009 - 03:11 PM

I could be wrong, but I think the intent of the author was (pos > 0) ? L[i] :L[i-1] Perhaps someone else could be more specific, but can you show us either the source or the link to the source so that we can see what context it's in. Thanks

This post has been edited by erik.price: 08 June 2009 - 03:11 PM

Was This Post Helpful? 0
  • +
  • -

#3 Oler1s   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1397
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: C conditional

Posted 08 June 2009 - 03:11 PM

Quote

H i have this C code, that I found in a solved example:
If that code really came from that example, it's very much "working" and not working.

Quote

I know that ?: is used like if-then-else statement.
The end result is the same, but ?: forms an expression. However. there is no operator <?= . Possibly the only way that code worked was the author used a preprocessor define.
Was This Post Helpful? 0
  • +
  • -

#4 NickDMax   User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: C conditional

Posted 08 June 2009 - 03:15 PM

While I thought maybe that was one of those elusive trigraphs (a throw back to the distant past) -- but it is not -- it is most likely a typo as that is a syntax error in C.
Was This Post Helpful? 0
  • +
  • -

#5 tashe   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 107
  • Joined: 10-March 09

Re: C conditional

Posted 08 June 2009 - 03:24 PM

Here is the code. It is posted as a solution to a contest problem. But when I compiled it with Dev C++ it raised an error.

#include <cstdio>

int A[1001][1001]; // numbers

int B[1001][1001]; // B[r][s] is sum A[r][1..s]
int C[1001][1001]; // C[r][s] is sum A[1..r][1..s]

int D[1001][1001]; // D[r][s] is sum A[r-b+1..r][s-a+1..s]
int E[1001][1001]; // E[r][s] is sum A[r-d+1..r][s-c+1..s]

int F[1001][1001]; // F[r][s] is minimum E[r][s-f+1..s]
int G[1001][1001]; // G[r][s] is minimum E[r-e+1..r][s-f+1..s]

int n, m, a, b, c, d, e, f;

int x[1001], y[1001];
int L[1001], R[1001];

void minimum( int k, int n ) {
   int pos = 0; 
   for( int i = 1; i <= n; ++i ) {
	  L[i] = x[i];
	  if( pos > 0 ) L[i] <?= L[i-1];

	  if( ++pos == k ) pos = 0;
   }

   for( int i = n; i > 0; --i ) {
	  if( --pos < 0 ) pos = k-1;

	  R[i] = x[i];
	  if( pos < k-1 ) R[i] <?= R[i+1];
   }

   for( int i = k; i <= n; ++i ) 
	  y[i] = L[i] <? R[i-k+1];
}

int main( void ) {
   scanf( "%d%d%d%d%d%d", &m, &n, &a, &b, &c, &d );
   e = a - c - 1;
   f = b - d - 1;

   for( int i = 1; i <= n; ++i ) 
	  for( int j = 1; j <= m; ++j ) 
		 scanf( "%d", &A[i][j] );

   for( int i = 1; i <= n; ++i ) 
	  for( int j = 1; j <= m; ++j ) {
		 B[i][j] = A[i][j] + B[i][j-1];
		 C[i][j] = B[i][j] + C[i-1][j];
	  }

   for( int i = b; i <= n; ++i ) 
	  for( int j = a; j <= m; ++j ) 
		 D[i][j] = C[i][j] - C[i-b][j] - C[i][j-a] + C[i-b][j-a];

   for( int i = d+1; i < n; ++i ) 
	  for( int j = c+1; j < m; ++j ) 
		 E[i][j] = C[i][j] - C[i-d][j] - C[i][j-c] + C[i-d][j-c];
   
   
   for( int i = d+1; i < n; ++i ) {
	  for( int j = c+1; j < m; ++j ) 
		 x[j] = E[i][j];	
	  minimum( e, m );
	  for( int j = a-1; j < m; ++j )
		 F[i][j] = y[j];
   }

   for( int j = a-1; j < m; ++j ) {
	  for( int i = d+1; i < n; ++i ) 
		 x[i] = F[i][j];
	  minimum( f, n );
	  for( int i = b-1; i < n; ++i ) 
		 G[i][j] = y[i];
   }
   
   int solution = -1;
   int piramida_r, piramida_s;
   int grobnica;
   int grobnica_r, grobnica_s;
   for( int i = b; i <= n; ++i ) 
	  for( int j = a; j <= m; ++j ) {
		 int score = D[i][j] - G[i-1][j-1];
		 if( score > solution ) {
			solution = score;
			piramida_r = i - b + 1;
			piramida_s = j - a + 1;
			grobnica = G[i-1][j-1];
		 }
	  }

   for( int i = 0; i < f; ++i ) 
	  for( int j = 0; j < e; ++j ) 
		 if( E[piramida_r+d+i][piramida_s+c+j] == grobnica ) {
			grobnica_r = piramida_r+i+1;
			grobnica_s = piramida_s+j+1;
		 }


   printf( "%d %d\n", piramida_s, piramida_r );
   printf( "%d %d\n", grobnica_s, grobnica_r );
			
   return 0;
}


This post has been edited by tashe: 08 June 2009 - 03:26 PM

Was This Post Helpful? 0
  • +
  • -

#6 NickDMax   User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: C conditional

Posted 08 June 2009 - 03:52 PM

where did you get it? That is not valid C++

Maybe it is a C++/CLI thing?
Was This Post Helpful? 0
  • +
  • -

#7 tashe   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 107
  • Joined: 10-March 09

Re: C conditional

Posted 08 June 2009 - 03:58 PM

It is not in English:

link

I substituted it with:
if( pos > 0 ) {
		  if(L[i] < L[i-1]) L[i] = L[i-1];
		  }


and sometimes it gives correct results sometimes doesn't.
Was This Post Helpful? 0
  • +
  • -

#8 janotte   User is offline

  • code > sword
  • member icon

Reputation: 991
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: C conditional

Posted 09 June 2009 - 04:07 AM

"sometimes it gives correct results sometimes doesn't. "

Yep that's why your compiler might give you a warning like this:
"DIC.cpp:24: warning: minimum/maximum operators are deprecated"

I assume this is quite old code?
We no longer use the min/max assignment operator (which was never part of standard C++)

Have a read here
http://gcc.gnu.org/o....0.4/gcc_6.html
and here
http://gcc.gnu.org/m...9/msg00299.html
for some info on what the operator did and how to modernise the code.
Was This Post Helpful? 1
  • +
  • -

#9 NickDMax   User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: C conditional

Posted 09 June 2009 - 07:41 AM

WOW!!! I didn't even know those ever existed. You must be very old. :) (or just better at Google than I am).

Cool info though.

Though I suppose the GCC probably gave you the hint with the error message... My compiler was not so helpful.
Was This Post Helpful? 0
  • +
  • -

#10 tashe   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 107
  • Joined: 10-March 09

Re: C conditional

Posted 10 June 2009 - 02:08 AM

thanks for the answers guys. It helped :^:
Was This Post Helpful? 0
  • +
  • -

#11 janotte   User is offline

  • code > sword
  • member icon

Reputation: 991
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: C conditional

Posted 11 June 2009 - 04:48 AM

View PostNickDMax, on 9 Jun, 2009 - 06:41 AM, said:

WOW!!! I didn't even know those ever existed. You must be very old. :) (or just better at Google than I am).

Cool info though.

Though I suppose the GCC probably gave you the hint with the error message... My compiler was not so helpful.


All three (age, Google and "gcc") have fair bit of truth to them.
The only regrettable one is the first one :D

This post has been edited by janotte: 11 June 2009 - 04:49 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1