Jump to content

Few C questions

- - - - -

  • Please log in to reply
7 replies to this topic

#1
skypower

skypower

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
Hello, I need to finish an exercise within 2 hours so please I need some help because I am going crazy.

void Deksia (char pinakas_Crypt[], char *pinakas_Words[],int m, int n, int i, int j)
{
     int metritis=1, c;
     n=0;

     for (j++;)
     {
          n++;
          if (*pinakas_Words[m][n]=="\0")
          {
               for (c=metritis;c==0; c--)
               {
                    j--;
                    pinakas_Crypt[i][j]=toupper( pinakas_Crypt[i][j] );
               }
          }
          if (c==0) break;
          if (pinakas_Crypt[i][j]==*pinakas_Words[m][n])
          {
               metritis++;
          }
          else
          {
               break;
          }
     }
}
First: the while(true) doesn't work in linux (it says something about true not declared)
Next: is the for loop wrong? I am sure I read somewhere it's not but I get an error!
QQ: I got an error about pinakas_crypt and pinakas_words

Help plx! :D

Edited by skypower, 03 May 2010 - 10:26 AM.


#2
Lance

Lance

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 276 posts
Linux is not guilt of giving wrong information.

You should name you source file something.cc or something .cpp, and then

g++ something.cc -O2 -otest

That should fix your problem.

#3
Lance

Lance

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 276 posts
true is a c++ keyword. In c, there is no built-in boolean type, hence, true, false, bool means nothing to c unless you instruct it on how to interpret them.

BTW, I failed to spot "while(true)" in your code. You must have hidden it somewhere else :)

#4
skypower

skypower

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
I changed it to for(j++;) which seem not to work. However I am done with the exercise and thanks for replies anyway. Instead of while(true) I wrote while(1) since true=1 I guess.

#5
MeTh0Dz

MeTh0Dz

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,119 posts

Lance said:

true is a c++ keyword. In c, there is no built-in boolean type, hence, true, false, bool means nothing to c unless you instruct it on how to interpret them.

BTW, I failed to spot "while(true)" in your code. You must have hidden it somewhere else :)

Wrong.

C99 has stdbool.h, which includes bool, true, and false.

#6
Turk4n

Turk4n

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 3,847 posts

MeTh0Dz said:

Wrong.

C99 has stdbool.h, which includes bool, true, and false.
That's true, also wondering, normally doesn't C use 0 as false and 1-255 for true?

Edited by Turk4n, 04 June 2010 - 10:05 PM.
TYPO

Posted Image

#7
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200

Turk4n said:

That's true, also wondering, normally doesn't C use 0 as false and 1-255 for true?

C++ accepts a non-zero integer, but I dunno about C if it allows over 1.

Quote

There is no keyword in C. Instead booleans in C are the same as integers with a value of 0 for false or 1 for true. Thus the following is an infinite loop:
while(1) {
; /* do nothing */
}


#8
bobdark

bobdark

    Programmer

  • Members
  • PipPipPipPip
  • 164 posts
regarding the for loop, change it to (;;j++)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users