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

Ah... tricky, thanks. Then
to see each character.

Hmm... no its incorrect. Correct one is:

cout << letters[i] <<" appears "<< counter[i] << " times\n";
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Since 48 is the ASCII value of character '0'.

It would be better if you replace 48 in your formula to '0' since it would make more sense and you dont have to remember all the integer equivalents of the different characters. Just using random literals in teh program makes it difficult to understand for others and even for you after some time has elasped.

In short just mysterious literals should be avoided, follow my method and use '0'.

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

Ah... yes thank you "Father" :D

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

Okay, the thing is that moderataors arent allowed to post code to help people out, its against the rules so I will just give you a short tutorial.

For learning about loops go here
http://www.cprogramming.com/tutorial/c/lesson3.html

For learning about accepting user input go here
http://www.cprogramming.com/tutorial/string.html

For use of toupper function go here
http://www.cprogramming.com/fod/toupper.html

Create a program from start with the help of these tutorials, adding feature one by one so that you dont mess it up, and then post your new program.

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

Did you read the algo I posted above? It exactly describes how you should go about finding freqency count.

And btw is there any restriction on using in built functions in your assignment, coz there is a function toupper( ) which accepts a character and returns its uppercase. So you should use that function instead of writing your own.

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

Hmm.. ok I will give you a simple algo, you attempt it and post your code if you get stuck:

  • Create a variable character count which counts the non uppercase chars and initialize it to zero.
  • Create an array of 26 integers and initialize it to zero. This array will keep track of the uppercase alphabet count.
  • Accept the input ( uppercase and other characters ) from the user into a array of characters ( C style string ).
  • Loop through the character array from the start ( i.e. position 0 ) till the end of string is encountered ( '\0' ).
  • For each character use the isupper( ) function to check whether the character is upper case.
  • If yes then increment the value corresponding to that character in the array. (Hint characters are actually integer values, so manipulate them to obtain the correct array index.
  • IF the char is not uppercase then just increment the count var.

Hope it helped, bye.

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

Also, you have to bribe the Super Mods big time. That's the only way they even consider you...either that or I've been ripped.

lol good one mate.

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

What's wordstream.h linkedlist.h?

Please label which one is which for clarity

I think he hasn't posted those files.

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

Naa you aint defining the default constructor, you are just declaring it in Complex.h but its defination doesnt occur in Complex.cpp, thats the whole root of the problem.

Implement one in complex.cpp and all should work out fine.

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

Just replace the y in cout with your character.

char mychar = '*' ; // this is how we declare and initialize characters

// your loops here
cout << mychar ;
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

yeah I got how to reverse the first loop it was the second one that is confusing me still. I should made that clear when I posted

Like Mr. Lerner said there, unless you yourself understand what looops are and how they function, it would be a tough time for you.

Just keep in mind that the inner for loop is executed outer for loop number of times.

For each iteration of outer loop,
Run the entire inner loop.

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

Okay, I will just like you to try out one thing if possible by you.

Create a new console C++ project in VS 2005. Create three blank files in it: Main.cpp, Look.cpp and Look.h

Copy and paste the contents of the original files into these files, check to see if all the new files created are in the same folder and same view.

I cant tell you the specifics of VS 2005 since its currently not installed on my computer .

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

Okay lets put it this way:

  • You need an output like:

1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7

  • Notice that the ending number of each line keeps on decrementing each row. For eg. its 9 for the first row, 8 for teh second row and so on.
  • So.. use a for loop which will count from 9 down to 1 (keep the variable of this for loop as outer.
  • Use a second for loop to control what gets printed. Keep the initial value of that for loop as 1 since 1 is common to each column that is printed. Name this for loop variable as "inner". Keep the terminating condition of this for loop to be less than or equal to "outer".
  • This way, your outer for loop takes care of the number of columns that should be printed while the inner for loop actually prints them.
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hmm... are all the files in the same folder ?
Have you checked the project settings of visual studio for this particular project ?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
int main(void)
{
    long double sourcebase; 
// why long double, why not just long or
//  int. long is sufficient for your needs.
// also initialize variables as you declare them to avoid bugs

     int targetbase = 0; // initialize variables, good practice
    int tmp_number = 0;
    int* new_number = NULL;
    int  flag = 0 ; // to check whether number entered is valid or not

    // pull stmts which dont require validataion out of loop
    printf("Enter a positive number: ");
    scanf_s("%d",&tmp_number);
    printf("Enter the destination base: ");
    scanf_s("%d",&targetbase);

    do 
   {
        flag = 0 ;
        printf("Enter the base of that number: ");
        scanf_s("%d", &sourcebase);

        if( (sourcebase<2) || (sourcebase>10) )
        {
             printf ("You number is invalid!!!!!!!\n\n");
             flag = 1; 
         }
    }
   while( flag );

 int i=0;
 int decimal=0;

while( temp_number ) // you forgot something ?
    {
        decimal += (tmp_number % 10) * pow( sourcebase, i ) ;
        tmp_number /= 10 ;
        ++i ;
    }


//  int decimal=0; // remove this since this will reset the decimal value we just calculated

 while( decimal )
    {
        new_number[i] = decimal % targetbase ;
        decimal /= targetbase ;
        new_number = (int*) realloc( new_number, i + 2 ) ;
        ++i ;
    }

 // printf("You number is:%d",new_number);
// The above is the incorret way of printing values of an array
// Loop through the various elements like
// eg. long* my_array = {1, 2, 3, 4} ;
// for( .... )
// { print values }
    
return 0;
    }

I hope you are understanding the things …

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

how do you become a mod?
there should be like tryouts, id be interested

It is basically a popularity contest. The super mod comes up with your name in the MOD forum, other mods voice their thoughts regarding your work and attitude and many other things. If you earn a majority, you are in. So keep posting and wait for the time when vacancies arrive:mrgreen:

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

Hmm please post your entire code so that i can have a look at it. My best guess is that you have declared new_number as an array of integers, which should actually be an integer pointer.

You must have done: int new_number [4] ; But you should have done: int* new_number = NULL ; Post your code which shows what you have done so far.

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

Hmmm... realloc is the memory management function which really makes the job of dynamic memory allocation actually "dynamic".

Dynamic memory when allocated using malloc , returns a pointer to the allocated peice of memory or memory block. But if the user wants to dynamically increase the size of the memory allocated to the same pointer, malloc wont do hte job.

To expand or to allocate more memory to the pointer which already has been allocated memory using malloc , we use realloc ( reallocation of memory ).

Consider this snippet:

// result stored in the dynamically allocated integer array with
// one slot
    int* new_number = (int*) calloc( sizeof( int ), sizeof( int ) ) ;

    i = 0 ;
    while( decimal )
    {
        new_number[i] = decimal % target_base ; 
        decimal /= target_base ;

        new_number = (int*) realloc( new_number, i + 1 ) ;
// we need more memory, which will be controlled by the counter i 
// hence while reallocing we use i as reference. So when i = 1
// allocate (2 + 1) = 3 slots and so on.

        ++i ;
    }

realloc takes two arguments, the first one being the pointer which has to be reallocated memory and the second one being the new size of the memory to be allocated.

For more info look here:
http://www.cplusplus.com/ref/cstdlib/realloc.html

Hope I have been helpful , bye.

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

Try replacing #include <asm/io.h> to #include <sys/io.h> and tell me what you get.

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

while (temp_number) means continue with the loop while temp_number is not 0. Inside the loop I am dividing the temp_number with 10 ( temp_number /= 10 ) so the loop ends when this value reaches 0.

eg.
Initial value = 129
129 / 10 = 12
12 / 10 = 1
2 / 10 = 0 ( loop ends )

Hope it made matters a bit clear for you.

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

while constructs and for constructs are both looping constructs -- you can use either one of them for looping purpose if thats what you wanted to ask. decimal += (tmp_number % 10) * pow( source_base, i ) ; Here decimal is the var which will hold the decimal value of the entered number with the base "source_base". To it we iteratively add the digit * source_base ^ i.

Here digit is obtained by doing tmp_number % 10 while i controls the exponent value.

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

Okay I will give you the algorithm, you just try to implement it.

  • Accept the number, the source base and the target base from the user.
  • convert the given "number" having base "source_base" into decimal using the formula:
while( tmp_number )
    {
        decimal += (tmp_number % 10) * pow( source_base, i ) ;
        tmp_number /= 10 ;
        ++i ;
    }
  • Now we have the decimal equivalent of the number in "decimal"
  • Create a dynamic array uisng pointer to int which will hold the individual digits of the new number of the target base.
  • Using the given formula convert from decimal to your base.
while( decimal )
    {
        new_number[i] = decimal % target_base ;
        decimal /= target_base ;
        new_number = (int*) realloc( new_number, i + 2 ) ;
        ++i ;
    }
  • In the end you would get your required number by traversing through the integer array.

Hope it helped, bye.

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

You actually wanted num_string as char array( C style string) but have declared it as being char which will hold only one character.

char num_string = '\0' ; // wrong
char num_string[BUFSIZ] = {'\0'} ; // correct, will now hold a number string

Also can you give a sample output your program is supposed to display, since it would help in clearing hte problem stmt which is not so apparent to me, seeing your imcomplete implementation.

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

THe sum of all hours or the total hours would be the sum of the individual hours which you accept from the user in th for loop. SO the logical thing would be to add to the total hours, the value of hours entered by the user.
Something like:

int total_hours = 0 ;
int total_charge = 0 ;

for( int i = 0; i < 3; ++i )
{
    // accept input from the user as "num"
    // calculate the charge for the hours inputted by user as "charge"

   total_hours = total_hours + num ;
   total_charge = total_charge + charge ;
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hmm.. I think there is some kind of misunderstanding here Mr. WaltP. His requirement is that the palindrome should be case insensitive as well as "ignore whitespace characters".

My first reaction is why bother with strtok()? This is a simple program of characters, not tokens.

Okay now i will try explaining my logic behind this. The OP wants the algo to ignore whitespace characters. So suppose your string is A (50 spaces) b (\n\t\t) B (100 spaces) a Trying to loop through the whole string to ignore whitespace characters is not feasible, would jsut result in reinventing the wheel when we have good inbuilt functions to handle such kind of situations. strtok is just the kind of thing we need here IMHO. Comments are welcome.

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

Dont worry about the code tags, its our daily routine to correct posts. Remember it though for the next time.

BTW just wanted to tell you that its 03.30 here :P ( so its never too late to code)

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

Ok that is a very good effort on your part.
I will write a crude code for you and will let you do the research on the inbuilt functions of C which i have used in achieveing the task.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char palindrome(char *,int);

/**
 * This function is used to remove the trailing new line which is normally present at the end of the string accepted from the user
 * using fgets( ).
 */
 void remove_newline( char* input )
{
    // loook up this func also at www.cppreference.com
    char* p = 0 ;
    if( p = strrchr( input, '\n' ) )
        *p = '\0' ;
}

char palindrome( char my_string[], int length )
{
    if( length < 2 )
        return 1;

    if( my_string[0] != my_string[length - 1] )
        return 0;
    else
        return palindrome( my_string + 1, length -2 );
}

void make_lower( char* input )
{
    // make string lowercase
    int i = 0 , string_length = strlen( input );
    while( input[i] != '\0' )
    {
        input[i] = tolower( input[i] ) ; // use std function to make string lowercase
        ++i ;
    }
}

char* format_string( char* input )
{
    // look up the function strtok, fgets, strcat and calloc at www.cppreference.com
    char* result = NULL ;
    char delimiter[] = " "  ;
    char* new_string = (char*) calloc( strlen( input ) + 1, sizeof( char ) ) ;

    result = strtok( input, delimiter ) ;
    while( result != NULL )
    {
        printf( "\ntoken: …
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hmm.. recursive palindrome checker.

As far as the ignoring spaces part is concerned, it would be better if you purged your string of spaces or newline characters before passing it to the Palindrome checker function. That way it would be cleaner and easier.

As far as the algo for recursive implementation is concerned, the logic is same as the recursive one, but you just need to write the function so as it can be called recursively.

  1. Create a function "is_palindrome()" which accepts the C style string which has to be checked for and the size of the string.
  2. During the first pass, the function would be supplied with the pointer to the start of the string and the original string length.
  3. Check if the strign length is less than one, if yes then the given string is a palindrome and return 1 or success. This is one way in which the function will be terminated.
  4. Now check if the first char of the string is the same as the last character. If yes then call the function again but this time with the character pointer incremented by one (to point to the next character under consideration) and the size parameter decreased by 2 ( since we have tackled two characters already-- the first and the last)
  5. If the first character is not equal to the last character, there is no point in continuing the function. Return failure or 0. This is the second terminating condition of hte …
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hmmm how about something like:

int hours = 0 ;
for( int i = 0; i < 3; ++i )
{
   cout << "Enter the hours parked: " ;
   cin >> hours ;
   // call your function and display the output in the format you want.

  // do whatever processing you want to do.

}
// end the for loop
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

LOoks like your concept of array indexing is a bit shaky.
If the array is declared as int binary[10], it contains 10 elements which can be accessed using binary[0] to binary[9].

If you use binary[10] you would be handling memory which doest belong to you and its called out of bounds exception.

for (i=9; i >= 0; i--)
        {
               binarySum[i] = binary1[i] + binary2[i] + overflow[i];

  // binarySum has indices from 0 to 8 since it has size 9
     // your very first iteration attempst to modify the 10th element
     // i.e. binarySum [9] which is not actually there.
     // the same problem is with your other arrays

            if ( binarySum[i] > 1)
                {
                    overflow[i-1] = 1;
                    binarySum[i] %= 2;
                }
        }
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Is your friend a well known software engineer or is there any specific reason you should listen to him ?
If he is a student just like you then you would be better off gettign your thoughts clarified at the forums rather than getting all the wrong ideas from each other.

And as far as the line char name[BUFSIZ] = {'\0'} ; It creates a character array name of size BUFSIZ which is a constant defined as #define BUFSIZ 512 in the standard library.

And by following it with {'\0'} , i am initializing all the elemnts of the array to null value i.e. '\0' .

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

But he says thatst the way his assignment is supposed to be.
Othewise the implementation of stack will never contain an array of viod poitners in its class defination.

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

I am not getting any errors on my compiler. I am usign MingW compiler.

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

Hmm yeah this thing has even happened to me quite a number of times..

Which browser you use Mr. Andor, i use Firefox ?

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

Hmm.. k now follow closely.
Suppose the character under consideration is the char variable my_char. You want to encrypt "z" and my_char is currently is the character 'z'.

1. Just to point out to you that char values are actually integers ranging from 0 to 255 ( 8 bits ). And according to the standard ASCII table the integer value for 'a' is 97 and 'z' is 122. So working with characters is actually working with integer or pure numbers.

2. What you want is to encrypt the char by addign one to it -- so first we will follow that step. my_char + 1 // this will give the required char 3. THe above process will work fine from 'a' to 'y' but when 'z' is encountered we want to loop back. So the extra work is required for this.

4. Next i do (my_char + 1 - 'a') % 26 This step is called normalizing or brinign the result in the required range that is from 1 to 26 ( here a -> 1st char, z -> 26 th char )

5. Now the output which i get will always be in the range of 0 to 25 irrespective of the character considered (try it out yourself and you will see)

6. But for our purpose we want actual char values and not normalized values so we again add 'a' to the whole result so that the result obtained are character values …

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

1. To make the program modify only characters you can use the function isalpha ( my_char ) which accepts a character and returns true or non zero value if the char is a alphabetic character. Thus before encrypting the character check the char using this function and it should work fine.

2. To make the program loop back from 'a' to 'z' you have to use some ascii mathematics... ((my_char + 1) - 'a') % 26 ; This should do the trick for loopback.

Consider my_char = 'z' then
(( 'z' + 1 - a ) % 26) + 'a' => 26 % 26 + 'a' => 0 + 'a'=> 'a'

HOpe it helped, bye.

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

Hmm.. i am not sure that i have got your question but:

int main( void )
{
    char name[BUFSIZ] = {'\0'} ;
    printf ( "Enter the string: " ) ;
    fgets( name, BUFSIZ, stdin ) ;

    int i = 0 ;
    for( i = 0; i < strlen( name ) - 1; ++i )
    {
        name[i] = name[i] + 1 ;
    }

    printf( "%s", name ) ;
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hmm.. I agree. Sad but true.

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

just to put you on the right path i am going to give a crude example of how it can be done using simple nested loops. Just understand the logic and implement it accordingly.

But it was not like i didnt warn him :D

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

Hmm.. just to put you on the right path i am going to give a crude example of how it can be done using simple nested loops. Just understand the logic and implement it accordingly.

int main()
{
    int n = 0, count = 0;
    char first_char = '*', second_char = '+' ;

    cout << "Input an integer: ";
    cin >> n;

    for (count = n + 1; count > 1 ; count--)
    {
        for (int inner = count; inner > 1 ; inner--)
        {
            cout << ((inner % 2) ? second_char : first_char) ;
        }
        putchar('\n') ;
    }
}

Hope it helped, bye.

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

Hmm... so post what you have attempted so far and I will try to see what can be done .

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

Are you sure you have got the pattern right, coz it seems a bit..weird.

If your question is related to drawing [search]pascal triangle[/search] like structure you can search for it in the code snippets section by clicking on the keyword above.

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

I forgot one detail...I can use cin on numeric data, but i cannot use it on text (except in main()) Scratch the above...I can use cin just not cin.get...why?

1 Some code:
/* Though my book is out-dated my compiler is new (Bloodshed 4.9.9.2, and i am running on a Windows 98 OS if that has any part in my misfortune. */

#include <iostream>
    #include <cstdlib> //What does this header do? LOOK HERE
    #include <iomanip.h> no .h is not needed
 
    using namespace std; //construct in C++ to avoid name clashes and 
                                    // to organize modules in a logical way 
 
    void TestCin(/*What goes here and why?*/);

    int main(int argc, char *argv[]) 
// argc - number of command line arguments
// agrv - array of char pointers -- basically array of C strings which
// are used to store the parameters supplied at teh command line
    {
        char TestCharGet[21];//Create TestCharGet as a character array
        cout << "Test the cin command\n";//output info
        cin >> TestCharGet;//Get TestCharGet
        cout << "\n" << TestCharGet << "\n";//output input
        system("pause"); // dont use non portable like this one
                                  // instead use getchar() for the same thing
        TestCin();
    }
 
    void TestCin()
    {
         system("cls"); // dont use non standard functions which make
                              // your code non portable

          char Toop[21]; 

         cout << "does it work\n";

         cin.get(Toop,21); // cin >> toop not safe ssince no bound
                                  //  check. You overwrite the mem that
                                 // doesnt belong to you

         // if you using C++ better use string instead of char …
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Factorial values may easily go out of hand and overflow due to their exponential nature. So if you insert very high values of "n" the output might overflow.

Please paste your output along with the input you giving, along with the function combination def. (just in case).

Also dont use system("pause") to stop the screen. Use getchar() to achieve the same function.

Long values are printed using the format specifier %ld which i dont see in your program.

Nothing more can be said unless you post your combination function along with the input which you supplied to it.

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

aw ok !
is this the right conversion from int double to void ?!
... = * (int *) ...;
...= * (double*)...;

Dont get what you are trying to say, quote an eg.

the hardest part is enum hahah lol how i'm gonna convert from sex to void* heheh thats pretty hard ! coz i faced alota of difficulties printing the sex struct...

*hint* enum values are in the end integer values.
male = 0, female = 1

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

IF thats the case then maybe you need the void* layer and not void* layer[100] . This way you can make layer point to any type of structure instance or any primitive data type var as you want.

And done that, you cant just print out the name of the structure instance. YOu need to write a custom function like you did back in the " qsort() " function probably a " display() " function.

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

Hmm i dont know what you are up to becoz sifting through your code i found this:void *layer[100]

What are you trying to achieve here? Do you know what it stands for?
It stands for layer as an array of 100 void pointers ?
Is that what you wanted ?

And please post the code with all the formatting and removing the commenting. It really is a big problem trying to find something suspicious from that code dump.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
...
void* pop(void) {return layer[100];} // replace with "return layer"
...
name[1].push(student[0].fname);
printf("%s",name[1].pop());

thank you

layer[100] stands for the character at position 99 and not the entire C Style array pointer. So what you are returning is the value of the 99th character as an addr of the string which is wrong.

Make the changes and tell me whether it works.

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

What exactly is your problem, compilation error, runtime error ?
Post your errors or detail the things which occur when you run your code.

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

What condition should occur if the user enters 'X' without filling the entire 512 element char array ? What if he enters the third character as 'X' then what should happen, what should the remaining array contain ?