~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

What you need to do SOS is learn everything you can, if you think just restricting yourself to c or c++ will be enough in the long run you are very much mistaken.

Learn as much as you can, in every language you can then you will have a better vision of how software integrates with each other on a grander scale.

Daniweb supports a lot of languages which is why I like it here, grab yourself a book and get stuck in!

Heh Mr. Iamthwee thanks a lot for the advice, will keep that in mind.
Just wanted to let you know that hearing this thing from many people I have decided to jump into the the most mysterious langauge -- Common LISP. Heard that it improves the programmers perspective about programming. The same goes with Haskell.

Anyways thanks alot for the advice (didnt know you had a non - sarcastic side :mrgreen: )

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

No, it more or less applies to both numbers as well as characters since in the end what you are doing is displaying the contents of an array which holds the frequency of occurance of something.

Your main concern here is to count the alphabets. It should be very simple:

1. Create an integer array with size 128 ( since we need only alphabets, we could have made it smaller, but no need to save a few bits ) and set it all to 0.
2. In the part where you check whether the character under consideration is a alphabet or not, update the value of the array to reflect that the alphabet has occured once. For eg. if the condition in your palindrome loop says that the current character is an alphabet, increase its frequency in the frequency table( use the relation between characters and integers for this thing)
3. At the end of the palindrome loop if the given string is a palidrome, display the frequency of each character using the code which you pasted above (of courese with some modifications)

Attemp atleast this and repost.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Tsk tsk... are you not forgetting something ?

Hint: Code tags, your histogram attempt, your current problems

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Post your updated code and tell us what you have attempted till now for histogram.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hmm dont you have a reference book which you learn from. Please read the things required for your assignment before you ask for help.. that way it makes our job easy .

BTW I will not give you direct answer, just a hint,

A function consists of
1. Function name
2. Return type
3. Function parameters

To call a function, its call should go along with the defination or prototype of the function.

Your function prototype is : void remove_newline( char* input ) ; while your function call is: string = remove_newline( char* my_string ) ; Dont you think something is wrong here. Also once you specify the datatype of the argument which your function accpets in the prototype, you need not specify it again in the functino call.

Think a bit, refer notes and try to come up with the best possible answer.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Look what can happen if you spend a lot of time on DaniWeb!
The government will probably legislate a warning sticker soon!

Heh what a thing to say :mrgreen:

Come to think of it... maybe you are right !

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I thought I called the function here:

void remove_newline (char *my_string);

NO this is a function prototype, which I asked you to move outside main(). And you call a function with something like:

(return variable = )function( parameters ) ;

Call the function after accepting input from the user.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

If that is what happnes in your case, then I think Wolfpack is right. You dont have the required codecs and windows media players err... is not a very good player and hangs up very easily when some unidentified format is being played. Best go with VLC and you should start kicking some video a**.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Okay you are not callling the remove_newline( ) function. And you havent moved the function prototype outside main( ). If you dont listen closely to what I say, it would really discourage me from helping you out, coz it makes me think my efforts on you are going to waste.

Make changes and then try to test the code. I think the newline is causing problems, call remove newline and it should start working.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Ah my bad.. maybe I am just going senile. Not used to writing function prototypes in main( ) and would advise you the same.

"Keep the function prototypes outside main ( ) preferably after the includes and before main ( )"

And now to the main part, what kind of errors or bugs where you gettting ?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Depends..
10 - 18 hours a day.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

FLCL
Naruto
Samurai Champloo
Innocent Venus
Black Lagoon
Death Note
Ouran High School Host club
Air Gear
D Gray Man
Black Blood brothers

and many more.... :D

arjunsasidharan commented: nice collection of animes bro!!.. i thought you like getbackers? +1
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Just to let you know there are many people who come here who fall in the age range of 10 - 15 and YES for me these are kids so dont think you are the yongest here :D. I did render help to a child who was 10 yrs old and wanted to start programming.

And when I say kid, it is in the sense they have just started learning programming.

Sheesh.. Dont know why dont kids dont like being called a kid :D

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Wow that sure is some dream. BTW do you really have a girlfriend or even that was a part of your dream :D

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Anyone else using Firefox have issues if they click the link above??

No I dont have any issues with this thing, it just asks me to save the file to a specified location

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I guess it's the story of my life. Always at the end of the line.

Just wanted to quote two things:

With great powers comes great responsibility

The grass is always greener on the other side

Regards,
~s.o.s~

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
int main(void)
{
    char my_string[80];
    int ispalindrome=1;/*boolean value True*/
    int i=0;
    int j=0;
    void remove_newline (char *); 


/* get the user input */
    

    printf("Enter a string no more than 80 characters ");
    fgets(my_string,80,stdin);

     void remove_newline (char *my_string);
 
    
    int string_length=strlen(my_string);

     if(my_string[string_length-1]=='?'||my_string[string_length-1]=='!'
     ||my_string[string_length-1]=='.'){
         
  /*If the last character is a ?,! or . continue with normal operation*/
   
    j=string_length-1;
    i = 0;

    
    while((i <= j && ispalindrome )){
     while ( ! isalpha( my_string[i] ) ) 
     {
          ++ i ;  
     }

     while( ! isalpha( my_string[j] ) ) 
     {
           --j ;
     }

        if(tolower (my_string[i]) != tolower(my_string[j])) {
      ispalindrome = 0;

        } 
        i++;
         j--;
    }
          if(ispalindrome) {
        printf("%s is a palindrome!\n", my_string);
        }
        else {
    printf("sorry, %s is not a palindrome\n", my_string);
  } 
     }
     else{
         printf("Your input must be terminated by a punctuation mark\n");
     }
    
  
return 0;
}
void remove_newline (char *ch)
 
{
    char *s;
    s = (char *) strchr(ch,'\n');
    if (s)
    *s='\0';
}

Does your code even compile ? which compiler are you using ? Wait let me guess.. is it Turbo C ?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hey there, didnt you find a smaller code than this. ;)
For your first opengl code this is actually too much.

And just to make you aware of the hard facts--

1. What kind of expertise do you hold in C / C++ ?
2. Do you understand what is a state machince since OpenGL uses FSM model and it itself is a FSM ?
3. Do you know what callback functions are ?

Dont you think that for a person, who wonders what are the uses of loops, you are looking too far ahead ?

Even I have tried my hand at game development and believe me, its not easy. Even when using a third party graphics library like Irrlicht, it took us nearly 2 years to understand, design, code and create a game.

Dont you think you are taking too big a leap ?

My personal advice: Kick start your gaming career by writing good C++ programs and get involved in console based programming. Just copy pasting some openGL code and running it wont give you any satisfaction because you havent put any effort in it as such.

Learning things the hard way and then giving up on your dreams just because "some things wont run" has already been done by many people and I have seen such people.

To fall into such category or to be one day with Ubisoft -- the final decision rests in …

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I think the DaniWeb blogs are a great news source -- I'm happy to help in any way I can.

Now you're making me curious...

Me too!

Just told them about the part Daniweb as a whole is playing in the development of kids... and all that.
Hope it should get them hooked on this one.

And dont worry it is not something which would harm Daniweb in any way.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

clock

clock_t clock(void);
The function returns the number of clock ticks of elapsed processor time, counting from a time related to program startup, or it returns -1 if the target environment cannot measure elapsed processor time.

You can find the aproximation between tick count of processor and seconds by wathching how many tick counts get elapsed in one second or something like that.

PS: Its almost 3.30 AM here so now I would be signing off. would solve your queries tomo. Bye.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Done and done.

Also posted a touchy comment which would make their eyes water *sniff sniff*

Hehe. Glad I could help.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hah.. I am happy my first post here as the moderator of this forum was approved by Mr. Stymiee himself :D

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

:rolleyes: ok its amazingly scary how u saw through my guise...Its just getting too complicated,

Knock knock... I am the moderator... remember ...:D

while((i <= j && ispalindrome ))
{
     while ( ! isalpha( my_string[i] ) ) // you had forgotten to write the string name
     {
          ++ i ;  // move ahead
     }

     while( ! isalpha( my_string[j] ) ) 
     {
           --j ;
     }
     
     // perform check here and exit if not same
}

Incorporate this somethign like this in your code and repost.

PS: Its almost 3.30 AM here so now I would be signing off. would solve your queries tomo. Bye.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Maybe you should read this.
http://www-ccs.ucsd.edu/c/time.html#clock

As far as the measuring of time is concerned, you can start the timer or measure the value of the clock at the start of the event and then query the time again when you want to know how many ticks has elasped.

// some code
double before = clock( ) ;
// some function here or some event started
double after = clock( ) ;

double time_elapsed = (after - before) / (the_scale_factor_of_your_game) ;

cout << "Time elapsed is " << time_elapsed << " since the magic spell was cast " ;

Hope it helped,bye.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Glad I could be of assistance.

Keep coding... :D

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I am getting comflicting information right now

...which is ?

but i think i'm going to leave out the termination I just don't think it is necessary if it is phrases like Ah! satan sees natasha will be invalid

Dont decide things your way, the assignment states that "all " palindromes should be verified.

and that just isn't sensible that can't be what he means I think

No he means exactly that thing. You are assuming wrong things.

Do you see what I mean

I see that you are trying to give up on this .

Post your problems.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Books for what ?
OpenGL or C++ ?

BTW did you read the thread which I pointed out in my previous post?
It features some of the free ebooks available on the net for OpenGL.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hmm.. it is always a good practice to divide teh work to be done by the program into functions... something you will have to acccept as you move on ahead in your course.. but still if you dont want then...

Anyways, there are a few minor problems with your code.

  1. Dont use gets ( ) . It allows the user to enter as many characters as he wants, thereby writing on the memory which is not of the users ( out of bounds array exception ) as well as leaving the input stream dirty.
    Better use fgets( ) the way i mentioned, which is a more robust fuction.

  2. while((i <= j && ispalindrome && isalpha(i) && isalpha(j) ))
    The problem with this code being that if it encounters a non character alphabet, it exits the loop to declare the result instead of ignoring the character. Pull the validation code i.e. the isalpha( ) part inside the while loop.

  3. You are performign some redundant calculations in this part of the code.

    if(tolower (string[i]) != tolower(string[j]))
    {
    ispalindrome = 0;
    }

    If the condition is not satisfied, there is no way the string is going to be palindrome, so why continue with the remaining calculations. Break teh loop prematurely is this condition is voilated.

Make the changes and repost.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

First thing:
1. You cant define functinos within functions, its not allowed in C / C++.
2.

int main(void)
{
    char palindrome[80];
    int ispalindrome=1;/*boolean value True*/
    int i=0;
    int j=0;

/* get the user input */
    do{

    printf("Enter a string no more than 80 characters ");
    fgets(palindrome,80,stdin);

// call remove_newline () function here

    j = strlen(palindrome) - 1;
    i = 0;

//////////The below one is a function !!!!///////////////////////
// you need to place it out of main( ) and then call it in main
// with the argument palindrome. Better name the string variable 
// palindrome to "input" or "my_string" to avoid confusion.

  /* Remove the trailing newline*/
     void  remove_newline( char* palindrome ){
       char* p = 0 ;
       if( p = strrchr( palindrome, '\n' ) )
       *p = '\0' ;
     }
/////////////////////////////////////////////////////////////

    int string_length=strlen(palindrome);
     if(palindrome[string_length-1]=='?'||palindrome[string_length-1]=='!'
     ||palindrome[string_length-1]=='.'){
         
  /*If the last character is a ?,!or . continue with normal operation*/
   
    j=string_length-1;
    i = 0;

// this part is unnecessary since fgets() makes sure you dont
// accept more than 80 chars from the user.

    if(j>80){
 /*finds out if characters or more than 80*/
    printf("Error your characters cannot be more than 80");
    }

////////////////////

// create a seperate function named palindrome rather than
// doing all the things in main ( ) itself.
 
    while((i <= j && ispalindrome && isalpha(i) && isalpha(j) )){
        if(tolower (palindrome[i]) != tolower(palindrome[j])) {
      ispalindrome = 0;

        } 
        i++;
         j--;
    }
          if(ispalindrome) {
        printf("%s is a palindrome!\n", palindrome);
        }
        else {
    printf("sorry, %s is not a …
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Take for example the "The Best Blogger contest" of Daniweb wherein you get to win loads of stuff as well as a member badge saying you are the best blogger. People like such things a lot and are bound to participate in your forum activities to make a mark.

Also keep contets for choosing moderators and super moderators for your forums like the one with maximum posts (non spam) till this and this date will be appointed a moderator of so and so section.

Hope it helped, bye.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Thanks, S.O.S. :o

I know I am a bit late for this but.... the pleasure is all mine :mrgreen:

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Edit your code and post your code in code tags, so that it will be easier for me to read. Read this link.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Bravo !!

Now that you have grasped the concept of what exactly a palindrome is , you can start coding it and then post any problems you encounter.
And please indent your code properly, so that finding errors and giving suggestions becomes simpler.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Okay it seems like you are confused between the requirement for the string to end in puctuation marks with teh concept of palindrome.

Palindrome doest care about the character case ( be it upper case or lower case ), it ignores whitespaces ( tabs, newlines, etc. ) and also ignores special characters and puctuations. It only and only cares about characters.

Terminating the string with punctutations is just a requirement of hte program, dont confuse it with palindromes.

So based on the explanatino above I ask you to tell me whether the strings given below are palindromes so that i can know you have grasped the concepts well.

De e , d
DEed
!!Deed !!!!
Deed.
Deed ?
?deed?
__de__ed__?

Give me the answers ?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Okay the algorithm I pointed to you applies in this case, you just need to keep in mind that the last char can be a ".", "?" or a "!" but cant be a ",".

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Even i am happy seeing you in action.

Just wanted to let you know the one who starts the thread can mark the thread by clicking on the link "mark as solved" which lies at the left hand top side of your web page.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

A string is terminatd by proper punctuations probably it is terminated using a full stop or should be somthing like:

Ah! Satan sees Natasha.

Can you write down here the actual requirements given to you, coz this is very confusing for me. Just copy and paste the requirements given to you for me to read it.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Okay try this: ( according to the requirements )

1. Accept the input from the user.
2. Check if the last character is a !
3. If it is continue with the normal palindrome processing as I have pointed out in the link before.
4. If the last char is not ! print out the message that the input is not in the specified format and then either exit the program or ask the user to reenter the string.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

In the project settings have you set the path for the header and library files of your SQL library ?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

So I hope your problem is solved ?
Can I mark this thread as solved ?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Just one question before we move ahead... why do you need to terminate the string with a ! .

deed is a palindrome but deed! is not ( reverse them and you will know).
Also the algo which i described will not work for things like:

!!deed!

since that algo ignores anything other than alphabets, hence both:

!deed!!! and deed and deed!! will be considered as palindromes.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Scripting languages:
If you are familiar with C/C++ use Python.
If you are familiar with Java use Jython.
If you are familiar with Csharp use Lsharp (LispSharp).

Wow didnt know about that.. thanks a lot buddy.
BTW since i am a C / C++ Mod.. :mrgreen:

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Thanks a lot to eveyone and esp sharky. Will keep on helping others out.

Well if GoldenEagle was blowing a horn, then...

This is hardcore metal baby...:D

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Heh didnt expect my trivial advice to a beginner to choose his language will have so many takers and will spark this healthy a debate.

Whatever I said previously was just based on my choice or what I like the most, so if any of my points make you unhappy or agitated please forgive me. Maybe I will just need to develop a broad perspective so that I can absorb the most from Professionals developers like Mr. WaltP and Mr. Ned. I know that being at 30+ of age has its advantage of being a man of this world so a student like me has to learn a lot.

Happy it didnt turn out the way of "hey you noob watchya mouth, will u? " .

I'm glad to be part of the community with you

Same here Sir. (didnt know this thread will be attracting someone at 43 :D )

For a while there, I thought this was going to go the way of the bunsen burner when a statement is twisted to illogical extremes

Just wanted to let you know that English is not my mother tongue so I would really appreciate if you keep it simple :D

As am I. But he still calls me MR.

Respect and help others and the same comes back to you eventually thats what I think :D

Anyways thanks a lot to everyone for this healthy discussion.
(the OP will be shocked at the way …

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Yes its the same method.

For a well detailed and excellent algorithm see HERE.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

When I said printing out the individual elements of the character array, you should use the qualifier %c instead of %s in your print statement, since array elements are characters and not character pointers.

int string_length = strlen( new_number ) ;

      for( int j = string_length - 1; j >= 0; --j ){

  printf("Your number is:%s",new_number[j]);
      }
    return 0;

gives me an error is it the way i am printing?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Huh , which earlier program ?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

No need to actually reverse the string -- unless your application demands so. Just traverse the array backwards using the for loop and everything should work out to be fine.

int string_length = strlen( number ) ;
for( int i = string_length - 1; i >= 0; --i )
{
    // output chars
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Palindromes are basically related to alphabets, so to ignore whitespaces in general you can traverse the whole character array, processing characters only when the isalpha( my_character ) condition is satisfied, otherwise skip that character.

Something like:

while( ! isalpha( character ) )
{
    // skip the character and move on
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

>>system("cls");// is there anything else i can use to clear the screen?

No, there is as such no standard way to clear the screen. It is always compiler or OS dependent. So use it if you want, but your code will not be cross platform complaint.

I use scanf_s because my express compiler complains with scanf

Let it complain. scanf_s is not a standard C function.

new_number[k]=('0' + remainder); //Explain what u mean by "appending the remainder at the start"

What i mean is that:

You have a character array new_variable[50] = { '\0' } ; Now what you want to do is to extract out the remainder from the decimal number and convert it into a string.

while(decimal>0){

       /* Convert to Target Base*/
     
          remainder=decimal%targetbase;
          decimal=decimal/targetbase;
          new_number[k] = ('0' + remainder) ;
          --k;// I tried here but it prints garbage

  
          }

Instead of this, initialize k as k = 0 and start appending the remainder at teh start with something like:

int k = 0 ;

while(decimal>0)
{
   remainder=decimal%targetbase;
   decimal=decimal/targetbase;
   new_number[k] = ('0' + remainder) ;
   ++k ;
}

And display the number by looping through the array:

for( int i = 0; i <= k; ++i )
   // display each character