from C++ to C

how to convert this code

Page 1 of 1

3 Replies - 1569 Views - Last Post: 22 December 2005 - 04:54 PM Rate Topic: -----

#1 duygugvn  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 36
  • Joined: 31-October 05

from C++ to C

Posted 22 December 2005 - 12:59 AM

......
........
//int selected[50]={0};
.......
......
......

{

for(int i=0; i<24; i++){
arr[row][i]=rand()%2;
cout<<arr[row][i];
}

.............
............
................
..............





cout<<"count: "<<count<<endl;
int fit=(term1-1)*(term1-1)+(term2-3)*(term2-3)+(term3-13)*(term3-13);
//cout<<term1<<" "<<term2<<" "<<term3<<" "<<fit<<"\n";


these some pieces of my code... I do not know how to convert to C.especialy I could not understand //these slash:)
I do not have enough time last two days
help me!!!

Is This A Good Question/Topic? 0
  • +

Replies To: from C++ to C

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: from C++ to C

Posted 22 December 2005 - 08:14 AM

The double slashes indicate a single line comment. If you see them on a line, that means everything following the slashes on that line is commented out. As for conversion to C, very little needs to be changed. Making the assumption that the arrays contains integers:
int i;
 for(i=0; i<24; i++){
arr[row][i]=rand()%2;
printf("%d",arr[row][i]);
}


and
int fit;
printf("count: %d\n",count);
fit=(term1-1)*(term1-1)+(term2-3)*(term2-3)+(term3-13)*(term3-13);
/*printf("%d %d %d\n",term1,term2,term3);*/


This makes the assumption that all variables are integers. You can modify based on variable type.
Was This Post Helpful? 0
  • +
  • -

#3 duygugvn  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 36
  • Joined: 31-October 05

Re: from C++ to C

Posted 22 December 2005 - 04:08 PM

I have to ask this function definition....
I could not understand where it is used (BOOL)????....


bool collided(int arr[50][24], int row)

what is the meaning of bool is it related to C or C++???

if it is used for C++,what ı used for C which gives the same meaning
Was This Post Helpful? 0
  • +
  • -

#4 Mrafcho001  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 41
  • View blog
  • Posts: 769
  • Joined: 01-November 05

Re: from C++ to C

Posted 22 December 2005 - 04:54 PM

bool is like any other storage type (int, char, double, float) except it is only 1 bit big. Can only store 1 or 0. Thats why its boolean storage type.

bool functions return true or false, nothing else.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1