xavier666 56 Junior Poster

Can you please provide us with the code?

xavier666 56 Junior Poster

Damn! Mike was too fast.
Nice one mike_2000_17!

xavier666 56 Junior Poster

Well, I'm a noobie but when I have to send an entire structure array, I just send the pointer to the 1st position of the array. Here is a sample code

# include <iostream>
using namespace std;

typedef struct AA
{
    int a;
}A;

void print (A *struc_point)
{
    cout << struc_point -> a << "\n";
}

int main()
{
    int i;
    A new_struc[5];

    new_struc[0].a = 1;             //  GIVING SOME RANDOM DATA
    new_struc[1].a = 2;
    new_struc[2].a = 3;
    new_struc[3].a = 4;
    new_struc[4].a = 5;

    A *pointer = &(new_struc[0]);   //  PUTTING THE ADDRESS OF THE
                                    //  1ST STRUCTURE VARIABLE IN 'pointer'

    for(i = 0; i < 5; i++)
    {
        print(pointer);
        pointer ++;                 //  GOING TO THE NEXT STRUCTURE VARIABLE
    }

    return 0;
}
xavier666 56 Junior Poster

Wow! You're so close! Just fill in the last two functions and you're done. Then you'll see that you don't even need our help.

You also need to attach the ass1.h file to your post and give proper code tags...

xavier666 56 Junior Poster
#include<conio.h>

This code hurts :O

I tried but could not find any other mistake which could have caused runtime error.. Can you please help!!

We here will not directly give you the answer. Check again. You'll find the error...
Give us the new corrected code...

xavier666 56 Junior Poster

Do you know this feature of characters in C?

char ch = 'A';
ch = ch + 1;
printf("%c", ch);

Output

B

Now, you said ASCII code of 'A' = 65 & ASCII code of 'a' = 90, hence try to figure how much you should add/subtract from a character to convert into uppercase/lowercase

xavier666 56 Junior Poster

You might wanna mark this thread as solved...

xavier666 56 Junior Poster

Are you trying to do something like this?

Enter The Number - 7

7 % 2 = 1
7 % 3 = 1
7 % 4 = 3
7 % 5 = 2
7 % 6 = 1

Your for loop is a bit faulty. If you can correct that, the program will run fine. Here is a cryptic hint; you have to remove something from the for loop. Then it'll run.

PS - This method of checking prime numbers is a bit time consuming.

xavier666 56 Junior Poster

I don't believe there is any standard method for reducing the text size.

This is the crux of the problem. You cannot view more than 50 lines at a time in DOS mode (as far as i know). But there is a trick. It involves pausing the screen after every 50 outputs. The algorithm is something like this

FOR LOOP ( START = 1 | END : WHEN START =  250 | INCREMENT START )
{    
    PRINT (VALUE OF START)
    IF (START IS A MULTIPLE OF 50)
    {
        PAUSE
    }
}

Convert this to code and i think you'll do fine ...

Or try this but I'm not sure whether this will work or not
Go to cmd, right click, properties -> options tab -> buffer size. Set it to 250. Set it for future use. Then try to run your program. Let me know of the results

xavier666 56 Junior Poster

And try not to use gets() . It's an erratic function. To cut a long post short, look here

tux4life commented: Exactly. +6
xavier666 56 Junior Poster

Also don't use conio.h . It is not a part of the standard C library. I guess you're compiler is quite outdated. I recommend Code::Blocks

xavier666 56 Junior Poster

An example you can see here occasionally a = c++ + ++c; The result of that expression is undefined because (most likely) it violates the rules you cited. Consequently the result store in a will be whatever the compiler writer decided it to be.

It recently came to my light about the functioning of a +++++ b, so I've decided to share

What does a+++++b mean?

The only meaningful way to parse this is:

a ++  +  ++  b

However, the maximal munch rule requires it to be broken down as:

a ++  ++  +  b

This is syntactically invalid:
it is equivalent to:

((a++)++) +  b

But the result of a++ is not an lvalue and hence is not acceptable as an operand of ++. Thus the rules for resolving lexical ambiguity make it impossible to resolve this example in a way that is syntactically meaningful. In practice, of course, the prudent thing to do is to avoid construction like this unless you are absolutely certain what they mean. Of course, adding whitespace helps the compiler to understand the intent of the statement, but it is preferable (from a code maintenance perspective) to split this construct into more than one line:

++b;
(a++) + b;

-Taken from Shiv Dutta's article on Best Practices For Programming. (Shiv Dutta - Technical Consultant, IBM, Software Group)

Source

xavier666 56 Junior Poster

You can also do this

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    int hiya;
    cout<<"hello world \n";
    getch();
    cout<<"enter a number \n";
    cin>>hiya;
    cout<<"you entered \n"<< hiya;
    getch();
}