tux4life 2,072 Postaholic

>Please guide me how can I access the data of a void type buffer?

Normally [B]malloc[/B] is used in a way like this:

int *p;
p = (int *) malloc( 50 * sizeof( int ) );  // allocate space for 50 integers

As you can see in the example above/below, the void pointer which is returned by malloc is casted to an integer pointer

int *p;
p = [B](int *)[/B] malloc( 50 * sizeof( int ) );

If malloc couldn't allocate the memory, then it returns a NULL-pointer, but using a NULL-pointer will almost certainly crash your whole program, that's why it's generally recommended to check the return value of malloc before using the pointer where you've tried to assign memory to...

Checking whether the allocation has succeeded can be achieved by something like this:

int *p;
p = (int *) malloc( 50 * sizeof( int ) );  // allocate space for 50 integers

if( !p ) {
    // out of memory
    // the memory could not be allocated
}

BTW, Don't forget to free the allocated memory as well, otherwise you'll have memory leaks in your program :)

Hope this helps!

jephthah commented: well put +10
tux4life 2,072 Postaholic

Start with this:

:)

tux4life 2,072 Postaholic

With me your code compiles (I'm using MinGW), but when running, your program will crash :)

tux4life 2,072 Postaholic

>Does anyone see the problem in C++ -source?
This code looks more like C than like C++ :)

tux4life 2,072 Postaholic

Please mention some link of curses tutorials.

To the OP and every other noob who is to lazy to use a search engine:

http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/
And all your ncurses related questions are covered here, including where to get it.

Wow, do you know how extremely difficult it was to get this link?
(It took me exactly 1 second by typing it in in Google and pressing the ENTER button on my keyboard :P)

tux4life 2,072 Postaholic

Another advice: I think the OP's problem is already solved, BTW did someone actually notice that this thread is more than one month old?

tux4life 2,072 Postaholic

Unrelated to this (sort of) i was cleaning out my house and must have found 2 CDs with windows 95 and floppy disks with 95 on them. (is that possible?)

This could be possible, but they're certainly not from one package :)

Windows 95 has existed in Floppy Disk version AND in CD version (though, the CD version offered some extra features) ...

tux4life 2,072 Postaholic

You forgot the end brace: if (s1.at(i) == s2.substr(s2.length()-i-1,1)[B])[/B] >pretty sure my logic is right?
No, I would have used if (s1.at(i) == s2[i]) instead of the above :)

tux4life 2,072 Postaholic

To the OP:

  1. > // paste code here
    We aren't going to post free code for you, however we can help you to accomplish the more tricky parts, give us a thorough problem description (not just: My program doesn't work, can you fix it for me?)
  2. We're not code rescue rangers or something, before developing any more programs, you should definitely consider taking a look at this *excellent* page first!
    (If you'd followed the process described there, you wouldn't have run into any problems :))
  3. Prevent the thread from becoming cluttered up by not every time reposting your whole code, just mention where you've changed your code or attach your code (as an attachment) to this thread, in that case the thread will be much easier to read...
Salem commented: Spectrum is green, and so is this cookie :) +33
tux4life 2,072 Postaholic

Write it as: (n->d).day , the '.' operator precedes the arrow operator in expressions :)

tux4life 2,072 Postaholic

>i don't want to use array.
In that case there's probably no other choice left than choosing for a Big Number library like GNU MP, it can handle much bigger numbers than a standard C++ datatype can...

And take a look at Salem's post as well:

  • What is your compiler?
  • What is your OS?
tux4life 2,072 Postaholic

From this thread I would suggest you to use: [B]unsigned long long[/B] :)

>can long long store 12 digit numbers.
Depends on what your compiler is...

tux4life 2,072 Postaholic

Consider this:

char *pointers[2];
char array[2];
pointers[0] = &array[0];
tux4life 2,072 Postaholic

There's a name conflict between the object 'movie' (which you created from your struct) and between your function movie:
I corrected the code by changing the name 'movie' to 'movies' for every instance of DVD:

/* I've also changed your include directives */

#include <iostream>
#include <string>
#include <list>


using namespace std;

struct dvd {
       string name;
       string director;
       string playtime;
       };
       
void movie(list<string> lista);
void director(list<string> lista);
void playtime(list<string> lista);
void write(list<string> lista);

int main(int argc, char *argv[])
{
    list<string> lista;
    list<string>::iterator it = lista.begin();
    for (int i=1; i<=2; it++){
    it++;
    }

    [B]dvd movies;[/B]

    movie(lista);
    lista.insert (it,[B]movies[/B].name);

    director(lista);
    lista.insert (it,[B]movies[/B].director);

    playtime(lista);
    lista.insert (it,[B]movies[/B].playtime);

    write(lista);
    lista.clear();
    write(lista);
    return 0;
}
void movie(list<string> lista)
{
    dvd [B]movies[/B];
    string M;
    cout << "Movie: ";
    getline(cin, [B]movies[/B].name);
    lista.push_back([B]movies[/B].name);
}
void director(list<string> lista)
{   
    dvd [B]movies[/B];
    cout << "Director: ";
    getline(cin, [B]movies[/B].director);
    lista.push_back([B]movies[/B].director);
}

void playtime(list<string> lista)
{
    dvd [B]movies[/B];
    cout << "Playtime: ";
    cin >> [B]movies[/B].playtime;
    cin.ignore(1000, '\n');
}


void write(list<string> lista)
{
    cout << "\nResult: \n";
    list<string>::iterator it;
    for (it = lista.begin(); it != lista.end(); it++){
        cout << *it << endl;
    }

}
tux4life 2,072 Postaholic

... And another one :P

User: Hi!
Cleverbot: You're not cleverbot.
User: No, did I say so?
Cleverbot: Yes.
User: No, I didn't.
Cleverbot: What's your point?
User: Who are you?
Cleverbot: I'm Bob.
User: Oh, k.
Cleverbot: Why would I die if I got wet?
User: Hi, Bob, May I ask you a question?
Cleverbot: Yes.
User: Can you do my homework for me? I really got stuck on working out 5*5.
Cleverbot: No.
User: That's not cool!
Cleverbot: Are you a male?
User: Yes, how many is five plus five?
Cleverbot: 35.
User: No, you're wrong.
Cleverbot: If I am wrong, what is your name?
User: Five plus five is 10.
Cleverbot: No, it's seven.
User: Mate, you're a very bad mathematician, its ten.
Cleverbot: Well, you're not a pirate. I don't wanna talk to you no more! You're silly.
User: Yeh, I know, self knowledge is the beginning of wisdom.
Cleverbot: On the news they said you could act almost human.
User: Really?
Cleverbot: Really.
User: Wow, that's nice.
Cleverbot: Yes, I know it is.
User: Can you please give me the area of the earth? I got that question on my exam of Geography, but I didn't know the answer.
Cleverbot: From looking at what?
User: Just the area of the earth, looking from …

tux4life 2,072 Postaholic

friend i m using gcc nd it is not giving ny error.....

According to the standard:

An array subscript is out of range, even if an object is apparently accessible with the
given subscript (as in the lvalue expression a[1][7] given the declaration int
a[4][5])

According to the rules of pointer arithmetic, negative subscripts are possible: int array[10]; array[5] is the same as *(array + 5)
array[-2] is the same as *(array - 2)

tux4life 2,072 Postaholic

>all is well but i do not have that "OTHER PROJECT TYPES "
That's because you're probably using an Express Edition, there are no Setup and Deployment Projects in the Express Editions...

>i beleive that windows vista could be part of the problem
No, certainly not, Visual Studio 2008 was designed to run on Vista :)

BTW, You could quickly have found this answer by Googling: http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvc/thread/abb8efd6-c44a-4767-8271-6cbe95286a42 (Found within a few seconds, on top of the list :P)

tux4life 2,072 Postaholic

friend i m using gcc nd it is not giving ny error.....

Welcome to the world of C!
It's not because it seems working that it actually works!

BTW, Why would you ever need to specify a negative subscript?
(Maybe because you want to write in some memory not belonging to your program?)

If you really want to see your program crashing, then try specifying a very big negative value, for example: array[-355465] = 56; :P
(However, I do NOT recommend this!!)

csurfer commented: Good one there tux ;) nice code to crash the program hahaha... +2
tux4life 2,072 Postaholic

Pavan, would you mind to post using code tags?

>is negative subscript of array allowed in C?
No, though you can achieve something like that by using pointer arithmetic, it can be very dangerous to do:

[B]// This is completely wrong and very dangerous![/B]
int array[20] = {0};
int *p = array;
*(--p) = 35;

>if yes then what is the meaning of it?
Undefined behavior!

tux4life 2,072 Postaholic

Take input in an char array and ......

To mention: a char array is not the only possibility, using a string is also possible :)

tux4life 2,072 Postaholic

*Clarification of Salem's post*
You have to change the order:

return 0;
[B]// The code below won't be executed[/B]
fclose(in);
fclose(out);

My advice is that you should never put code after a return statement, because when a return statement is executed, the function directly exits, so the code after the return statement won't be executed...

How to fix this?
Well, just change the order of the statements, like this:

fclose(in);
fclose(out);
return 0;

:)

tux4life 2,072 Postaholic

Friend u are suppose to give reason also why will u prefer ur approach?

Because you can dynamically expand it and because it doesn't use more memory than needed :)
(and when you pop elements, then you can free up the memory that was being used to store that element)

But the downside is that it's more difficult to implement, like Salem has already mentioned, you'll have to choose the one which fits the best in the type of application you want to write, for example, a stack implementation based on an array is also perfectly possible, it's even easier to implement, but you cannot dynamically expand it and when you don't fill up the whole array/stack, you're wasting some memory as well :)

So if you only want to store a fixed number of records, then I would rather go for the implementation based on arrays...

tux4life 2,072 Postaholic

if u are asked to implement a stack then what u prefer?

I'd go for something like this :)
(a stack based on a linked list)

tux4life 2,072 Postaholic

At which line declaration and statement are mixing?

Describing the problem:
Take a look at this:

int i,j;
float H [100][100];

FILE*in;
[B]in=fopen("0.txt","rt");[/B]  [B]// you make an assignment here (1)[/B]

FILE*out;
out=fopen("rotation0.txt","w");

(1): In C89 you aren't allowed to declare any more variables after the first statement (and in this case an assignment statement took place, before the declaration of other variables)

Fixing the problem:
The fix the problem, you'll have to place all declarations before the first statement, like this:

int i,j;
float H [100][100];

FILE*in;
FILE*out;

in=fopen("0.txt","rt");
out=fopen("rotation0.txt","w");
Salem commented: :) nicely put +33
tux4life 2,072 Postaholic

Also, it keeps a users online usernames and passwords just in case he forgot his account information.

All modern browsers (= all today's browsers) have something like a password manager which will safely guard that information for you and fill it in automatically for you when you visit that particular web page again, the only thing left is that you have to click the logon button :P

tux4life 2,072 Postaholic

What do you actually want to achieve using an USB port?
Your question was very vague...
Do you want to write some files to a USB stick?
Do you want to transfer data over a USB cable?
Do you want to control a wireless USB adapter?

USB has much applications :P

Edit:: Out of your post I could make up that you want to control a little motor over an USB port, is this correct?

tux4life 2,072 Postaholic

Hey guys,

I just want to know if its possible to code a java program that will automatically logs you on your online accounts (e.g. such as yahoo mail, facebook, gmail, multiply, or even in this site) using your own username and password you use to register on such accounts. If its possible, what codes or technique should I use?

And why would you ever want to do this?

tux4life 2,072 Postaholic


>Im New To c++, But Not New To Programming
>What Iz The Point Of A Array?

Haha! And you don't know the assets of an array?

Imagine you're a teacher and you've to write a program which deals with the pupils' scores, let's say you've twenty pupils in your classroom and you want to keep track of their scores of four tests...

In this case an array is preferred, though normal variables are possible, it's very unlikely and difficult to solve this problem, for example: you'll need 4 * 20 (= 80) variables to store all the scores...

Instead of doing it the difficult way (creating four variables for each pupil), an array is the method to solve this kind of problems.

Comparison: Solving the problem using an array - variables

  1. Using variables:
    int p1_s1; // pupil 1 score 1
    int p1_s2;
    int p1_s3;
    int p1_s4;
    int p2_s1;
    int p2_s2;
    int p2_s3;
    .
    .
    .
    (and so on)

    As you can see in the above example, using variables will be very time consuming (and your code will grow in size as well)

  2. Using an array:
    But using an array, you only have to write a single line of code to achieve the whole thing:
    int scores[20][4]; // or int scores[4][20];

Actually you can say that an array is a table / matrix :)
(and every separate element of the array is actually comparable to a normal …

tux4life 2,072 Postaholic

Or...take a look at this :)
( It's a better way than the way described in my previous post, sorry :$)

tux4life 2,072 Postaholic

Dear you are declaring a char ( char s1 = "" ). Its not a string fis=rst declare a string as
char s1[10]; // string s1 of 10 characters
char s2[10]; //string s2 of 10 characters
Now take input as
cin.getline(s1,10,'\n');
cin.getlin(s2,10,'\n');
Now compare two strings. It will compile and work.
I hope you enjoy it.

First some remarks:

  1. Explicitly specifying the delimiter in cin.getline(s1,10,'\n'); isn't necessary.

  2. char s1[10]; // string s1 of 10 characters
    You aren't taking the NULL-terminator '\0' into account.

  3. cin.getline(s1,10,'\n');: if you want this line to behave correctly then you should do one of the following:

    1. or, you change it to: cin.getline(s1,9,'\n');
    2. or you change char s1[10]; to char s1[11];

Same applies for s2 :)

tux4life 2,072 Postaholic

Not that difficult:
(If you understand how logarithms work, then this is a piece of cake :P)

The standard trick is to use the logaritm in base 10.

Let x = lg(8600!). Since lg(xy)=lg(x)+lg(y) you have

x = sum(lg(k),k=1..86000)

Define floor(x) as the integer part of x. Then

86000! = 10^(x-floor(x))*10^floor(x).

You can evaluate x to the degree of accuracy you want, for example,
using Maple I got:

86000! = 7.91222558*10^372239

The computation time was close to 0.

(Source: http://answers.google.com/answers/threadview/id/33709.html)

:P

Edit:: Remark, the above explanation is no real C code, but you can quickly adapt it...

tux4life 2,072 Postaholic

main() , this is not C++ !
In C++ it would look like: int main() :)

tux4life 2,072 Postaholic

Hi, siddhant3s, I think it would be more helpful to the OP if you indent your code, there's a nice article about code indenting available here :)

tux4life 2,072 Postaholic

>Write a C++ program that ......
No, YOU write it!

BTW, Read this before posting :)

tux4life 2,072 Postaholic

>try placing it directly in the video memory(0x40000000)
Haha, directly!
I assume the OP isn't using DOS anymore :P

tux4life 2,072 Postaholic

First read this, then you read this.

After that you change your code to use new-style headers, and then we're ready to help you :)

Change

#include<iostream.h>
#include<stdlib.h>

to

#include<iostream>
#include<cstdlib>

(if your compiler supports it, if your compiler applies to the C++ standard, then this shouldn't give problems)

Can you also please explain us what the point of your program is?
If it's your homework, can you describe the exercise then? (but in a better way)

tux4life 2,072 Postaholic

Can u please tell me how to do nesting of arrays of structures

What??

Edit:: Your (unformatted) code looks much more like C than like C++ !

iamthwee commented: You have a very good strategy to boost your rep. Good rep everyone however, you're a likeable person so I have no qualms repping you. +21
tux4life 2,072 Postaholic

The code to get input from the user is wrong, you should rather use:

cout<<"Please enter 3 negative values separated by a space for row1:";
[B]for(int i = 0; i < 3; i++)
        cin >> ARR[1][i];[/B]

(this applies to both: the positive and the negative values)

BTW, This doesn't work if you want to display an element of the array: cout<<"The array element:"<<i;

tux4life 2,072 Postaholic

>keeps getting me a window that says variable j being used without being initialized !

Ah, now I understand! That's because you declared variable j, but you don't give it a start value (= you don't initialize it), you may not assume that j will get the value zero automatically, but you can specify it like this:
Change line 10 of your code to: [B]int i = 0, j = 0;[/B]

tux4life 2,072 Postaholic

Ugh,,, why does this window keep appearing.. it says the variabla j is being used without bein initialized !! IT is initialized !
and am getting this as a compiler message:
1>------ Build started: Project: HW 12, Configuration: Debug Win32 ------
1>Linking...
1>Embedding manifest...
1>Build log was saved at "file://c:\Users\fofa\Documents\Visual Studio 2005\Projects\HW 12\Debug\BuildLog.htm"
1>HW 12 - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

According to your compiler's message your code is compiling perfectly...

tux4life 2,072 Postaholic

>Can sumone suggest me the easiest way to do it.

I think piping is the easiest way to do that :)
( No need for [B]fopen()[/B] :P )

Note:: Not all platforms support piping, though as far as I know Windows, Linux and Unix are all supporting it...

( But actually piping is no real programming so I would rather suggest you to stay with C's I/O Functions )

tux4life 2,072 Postaholic

>ops sorry.. this is the last code.. am not sure if i did what u told me right.. abt the absolute value..

Well, does it give the expected output? Then you're probably right, otherwise you've done something wrong :)

Edit:: You've made some logical mistakes in your code, take a good look at when you're filling row 1 and row 2?
The subscripts are wrong... (Change it also when outputting the array to the screen)

tux4life 2,072 Postaholic

William, regarding your post (#11): I think that int main( void ) is the preferred way in C :)

(take a look at this, first good answer)

tux4life 2,072 Postaholic

>i dunnu how to do it which is change negative variables to positive ones??

I think you mean the 'absolute value', take a look at this:

int a = -5; // a contains a negative value
a = abs(a); // a now contains 5 instead of -5

>but there were some errors that i couldn't fix

Well, you declare ARR as a two dimensional array, so this code is invalid: [B]cin>>ARR [i];[/B] (you always have to specify two subscripts if you're dealing with a two-dimensional array)

If your intention was to fill the first column of that array, then you could do the following: [B]cin>>ARR [i][0];[/B] :)

tux4life 2,072 Postaholic

>...but #include "stdafx.h" is missing
Please note that it's not needed for non-Microsoft compilers :)

tux4life 2,072 Postaholic

[B]void main()[/B] is evil, make it [B]int main()[/B] (read this)
#include <conio.h> remember that conio isn't a part of the standard C library :)

BTW, Why don't you use a switch statement for this?

Edit:: To the OP: Do you want to pause your program? Then take a look at this :)
Edit:: For the above post (#5): Rubbish code!

William Hemsworth commented: "make it int main()" ahh hah! I can blame you for making me use that :P +10
tux4life 2,072 Postaholic

I get tired of saying it: why does anyone use [B]system("PAUSE");[/B] ??

Isn't [B]cin.get()[/B] good enough? Is it maybe too fast ??

BTW, Take a look at my signature as well!
Edit:: And at this :)

tux4life 2,072 Postaholic

Aaaaaaaaaaargh! [B]void main()[/B] , don't use it, it's evil (check this page) !!
Use int main() instead :)

You should also read this.

A comment like this: [B]//variable decl of float type[/B] makes no sense, everyone can see that the declared variables are of type float.

Note:: This code looks more like C code, it's definitely no C++ !!

Salem commented: Yes! +32
tux4life 2,072 Postaholic

What does error Lnk 2001 and LNK 1120 mean? Am a complete noob.. Could anyone please give me a step by step procedure to rectify it?

How are we supposed to know this? We even don't know what compiler you're using :( (we need to know this because it can be compiler specific, I guess you're using a Microsoft compiler, but I want to be 100% sure :))

BTW, You could just Google on it ...

Edit:: Being a noob isn't wrong, as long as you learn from your mistakes and you follow the forum rules, we've nothing against you :)

tux4life 2,072 Postaholic

IMO (= In my opinion) (yea killdude, it's an opinion) you shouldn't use WinAPI for Graphics Programming, it's unportable (as already said by siddhant3s), and there are a lot of better and easier to learn Graphic/GUI Libraries available for cross-platform development, if you write your program, making use of such a library, then you can easily port your application to a wide range of operating systems (And in case of wxWidgets it still uses the OS' native API by default) :)

killdude>The files were not created by MS, they are created by BloodShed developers, see this code from <windows.h>
Wrong, this file was created by the developers of MinGW, the compiler where the Dev-C++ IDE relies on.