tux4life 2,072 Postaholic

You're wrong. If you pass a NULL pointer to atoi, your program will most lightly crash. If you pass a string such as "12Q34" then it will return 12, as it stops as soon as it reaches the first non-digit character.

Oh, he means 'fails' in that way, then I agree :)

tux4life 2,072 Postaholic

it should be like:

while(ages[4]!=1 || ages[4]!=2 || ages[4]!=3 || ages[4]!=4);

Possible, but the preferred way of doing this is using a range like this: while(!(1<=ages[4] && ages[4]<=4)); as I'd already mentioned :)
(It's much more practical if you use this approach, imagine that you've to check for all numbers from 0 to 100 manually, using your approach, I wish you the best with it :P)

tux4life 2,072 Postaholic

>Do you know what happens if atoi fails to convert?
Then a zero value is returned, or am I wrong?

tux4life 2,072 Postaholic

tux4life> [...] then you should try itoa
I hope you understand that itoa is not a standard C function.

Yes I know, thus actually this was a bad suggestion :(

What a way of missing the boat!
None of your suggestions are a solution.
The OP wants to have it display as a text.
e.i. 5 = Five, 6 = Six

You're totally right, I didn't read his question carefully enough :(

The simplest solution I know is by putting all the text representations of a number into an array, like this:

char *num[] = {
"",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"ten"
/* And so on ... */
};

Now if you want to convert the number 5 for example to "five" and display it on the screen, you just add the following line to your code: printf("%s\n", num[5]);

tux4life 2,072 Postaholic

int a = 50341; //declare const a=50341
Not sure why I need to create a const.

Can you refer me to the place where I mentioned that?
I don't think so as I didn't say you had to declare it as a const :P

BTW, post using code tags.

tux4life 2,072 Postaholic

My compiler didn't give any warning about this (even with all warning levels on). &(*blah[i]) is actually the same as blah[i] :)

tux4life 2,072 Postaholic

Hi,
I am new for writing plugins.Dont know how to start.Can any body provide link or sample codes for plugins.

Google on Browser Helper Objects :)

tux4life 2,072 Postaholic

Some remarks:

  1. const char *ini[]; will cause a compiler error because the size of this array isn't known.
    (You can solve this by putting the number of elements between the brackets ('') or by initializing the array)
  2. ini[i]=blah[i] , missing semicolon (';').
  3. This line: ini[i]=blah[i]; doesn't make much sense if the next line is: printf("%s\n", [B]blah[i][/B]); Perhaps you meant printf("%s\n", [B]ini[i][/B]); ??
tux4life 2,072 Postaholic

You forgot to add the line Input.open(); , same applies to Output :)

tux4life 2,072 Postaholic

Does Input.txt exist? (remember that it's case sensitive)

Replace this (line 26-30):

while(!Input.eof())
{
    getline(Input, Line);
    cout << Line << endl;
}

with this:

while(getline(Input, Line))
    cout << Line << endl;

or this:

getline(Input, Line);
while(!Input.eof())
{
    getline(Input, Line);
    cout << Line << endl;
}
tux4life 2,072 Postaholic

Hi, mate, this forum isn't made for 'testing' how your image is displayed :angry: !!
By the way, you even don't have a question and this thread isn't Java related !

tux4life 2,072 Postaholic

for($i = 86400; $i < 604900; [B]$i + 86400[/B]) has to be for($i = 86400; $i < 604900; $i +[B]=[/B] 86400) (otherwise your loop index always stays 86400 :))

:P

tux4life 2,072 Postaholic

Take a look at the following example:

#include <stdio.h>

void print_el(char **p, int el)
{
    printf("%s\n", p[el]);
}

int main(void)
{
    char *blah[] = {
    "string1",
    "string2"
    };

    print_el(blah, 1);
    print_el(blah, 0);

    return 0;
}

output is:

string2
string1

>how can I move to the next element of my blah array
Increase the pointer, e.g.: if p is a pointer then you'll have to write p++; to move it to the next element :)

tux4life 2,072 Postaholic

Correction of something in my previous post:

...
while (ages[4] != 1,2,3,4);
should be:
while ([B]!([/B]1<=ages[4] && ages[4]<=4[B])[/B]);
...

If you want something like an option menu, try this:

/**
@description: A simple option menu
*/
int opt = 0;
cout << "Available options: 1, 2, 3" << endl << endl;
do
{
    cout << "What option do you want?";
    if(!(cin>>opt))
    {
        cin.clear();
        cin.ignore(1024, '\n'); // remove bad input from the stream
        opt = 0;
    }
    switch(opt)
    {
    case 1:
        // code for option 1
        break;
    case 2:
        // code for option 2
        break;
    case 3:
        // code for option 3
        break;
    default:
        cout << "Please choose a valid option!" << endl << endl;
    }
} while (!(1<=opt && opt<=3));
tux4life 2,072 Postaholic

Do you mean STL's std::stack , or something of your own creation?

As he's talking about iterators, I assume he means the stack template from STL :)

tux4life 2,072 Postaholic

To the OP:
This page explains briefly what you want to do.

tux4life 2,072 Postaholic

Also possible.

tux4life 2,072 Postaholic

Yes, I need get number of vowels in the sequence.

Then you might want to take a look at this code snippet :)

tux4life 2,072 Postaholic
ages[0]='1';
ages[1]='2';
ages[2]='3';
ages[3]='4';

won't put the numbers 1, 2, 3 and 4 in the array :)
You'll have to write

ages[0]=1;
ages[1]=2;
ages[2]=3;
ages[3]=4;

Or you can truncate it by directly initializing the array: int ages[4] = {1,2,3,4}; while (ages[4] != 1,2,3,4); should be: while (1<=ages[4] && ages[4]<=4); Instead of writing:

if (ages[4] == 1)
  std::cout << "You choose [add]..." << std::endl;
else if (ages[4] == 2)
  std::cout << "You choose [subtract]..." << std::endl;
else if (ages[4] == 3)
  std::cout << "You choose [divide]..." << std::endl;
else if (ages[4] == 4)
  std::cout << "You choose [multiply]..." << std::endl;
else
  std::cout << "Sorry!!! choose one of the four listed

a switch is the preferred way to do this:

switch(ages[4])
{
case 1:
    std::cout << "You choose [add]..." << std::endl;
    break;
case 2:
    std::cout << "You choose [subtract]..." << std::endl;
    break;
case 3:
    std::cout << "You choose [divide]..." << std::endl;
    break;
case 4:
    std::cout << "You choose [multiply]..." << std::endl;
    break;
default:
    std::cout << "Sorry!!! choose one of the four listed << std::endl;
}

Actually you don't have to specify std:: each time before cout, endl, etc... as you're already including the following line in your code: using namespace std; :P

tux4life 2,072 Postaholic

If you only want to convert integers to a string, then you should try itoa :)

tux4life 2,072 Postaholic

So, you want to convert a character string to an integer variable, try atoi !

example:

char num[] = "5269";
int i;
i = atoi(num); // integer variable i now holds the number 5269
tux4life 2,072 Postaholic

Take a look at this code snippet :)
Or you could use a vector.

tux4life 2,072 Postaholic

I have problem to start. I need algorithm for program that prompts the user to input a sequence of characters and outputs the number of vowel, using user-defined value returning function Vowel.

Please help

So you want to count how much times a certain vowel is encountered in the sequence of characters?

e.g. : aabcc
a: 2
b: 1
c: 2

Is this right?

tux4life 2,072 Postaholic

>and i have #include <cstdlib> in my winMain
You don't have to include it in a function :P
Add that line at the top of your program's source file where you are using rand() in.

What errors are you getting?

tux4life 2,072 Postaholic

im trying to write a cg pixel shader and just want to generate a random number too offset the colour of a pixel

is there something i need to include, i tried using rand() but gave me errors

thanks in advance

rand() and RAND_MAX are both defined in cstdlib, so try adding the following line to your program: #include <cstdlib> :)

BTW, If this doesn't work, could you please post the code then?

tux4life 2,072 Postaholic

I tried in both IE7 and FF 3.5 Beta 4. Yeah I can get to the window, it just won't upload.

Same for me :)

What web browser?

Mozilla Firefox 3.0.10

tux4life 2,072 Postaholic

>I am pretty sure it is going to take me a while because I am not sure what every statement there does.
What lines of my code don't you understand?

tux4life 2,072 Postaholic

No, wait!!
I found a better option: convert the integer to a string using stringstreams and compare those two strings :)

int a = 50341;
stringstream ss;
string s, t("50341");
ss << a; // put the number in the stream
ss >> s; // take the number as a string out the stream
if(s==t) cout << "The integer's value is equal to the string's value." << endl;

don't forget to include sstream !

tux4life 2,072 Postaholic

I understand that. That isn't something I can impliment into the code I was hoping for. If there isn't a way to direction compare/match an int to a char; is there a way to do what I overall want? Maybe, once the console input occurs, "1 2 3" or such it can look into my string and retrieve what "is equal to" those digits? Or visa versa, " a b c", get those equivelent in the int array? Maybe using a "cin.get()", to find the proper string or int.
I appreciate all your help so far, I would have ben fighting with that for a long time.

The example I provided demonstrates how you could implement it ...
The one I provided was for digits, sorry my mistake, but you can adapt it so you can also compare a whole integer to a string :)

tux4life 2,072 Postaholic

I've uploaded them to imageshack: http://img188.imageshack.us/gal.php?g=daniweb1.jpg :)

tux4life 2,072 Postaholic

Uploading doesn't work?!

Nope, if I upload it, the uploading popup screen becomes white :(
(and I can't send a screenshot of this :P)

You could also just take a look at the index page of Daniweb and you'll see what I mean :)

tux4life 2,072 Postaholic

You cannot compare a string directly with an integer, please take a look at the following example:

string s="1a3";
int arr[]={1,2,3};

for(int i=0; i<sizeof(arr)/sizeof(int); i++)
{
    if((s[i]-'0')==arr[i])
        cout << "equal" << endl;
    else
        cout << "not equal" << endl;
}

output will be:

equal
not equal
equal
tux4life 2,072 Postaholic

Can you screenshot it please? Thanks!

Sure I can, look at the attachment(s) of this post :)

Edit:: Damn, uploading doesn't work, is there another way?

tux4life 2,072 Postaholic

I am having a problem with is matching up my array with the string. I am trying to use "array == string", because = is out of the question. I know I want it to say "is equal to", but that reads as a compilation error. Do you know what the correct operator would be?

Could you give us an example of the code you're trying to do this in?
(post the code where you have this problem with)

tux4life 2,072 Postaholic

Hi,

When you post a new code snippet, it is always announced multiple times on Daniweb's index page, is this normal or is this just an unreported bug?

tux4life 2,072 Postaholic
6.8.5 Iteration statements
Syntax
   iteration-statement:
      while ( expression ) statement
      do statement while ( expression ) ;
      for ( expressionopt ; expressionopt ; expressionopt ) statement
      for ( declaration expressionopt ; expressionopt ) statement

According to the C++ standard it's:

[U]6.5 Iteration Statements[/U]
iteration-statement:
    while ( condition ) statement
    do statement while ( expression ) ;
    for ( for-init-statement conditionopt ; expressionopt ) statement
for-init-statement:
    expression-statement
    simple-declaration
[ Note: a for-init-statement ends with a semicolon. —end note ]
tux4life 2,072 Postaholic

I would advice to use string streams (as already mentioned a couple of times):

const int N = 5; // number of elements in the long array
long a[N]={345,678,890,123,456}; // a simple long array
char str[N][5]; // the char array where we're going to store the converted longs in
stringstream ss; // our stringstream we're going to use for conversion

for(int i=0; i<N; i++)
    ss << a[i] << " "; // send all elements of the long array to the stringstream
for(int i=0; i<N; i++)
    ss >> str[i]; // take them back out the stream as a character string

Don't forget to include sstream :)

Dave Sinkula commented: Another fine option. +19
tux4life 2,072 Postaholic

tux4life >Unportable rubbish which doesn't work.
adatapost>Oh!!! Buddy you should have to test this code before judge.

I have tested it before I judged, I'm not stupid ...

tux4life 2,072 Postaholic

No, the matrix has 6 columns and unknown number of rows.

Then you should consider using a vector :)

tux4life 2,072 Postaholic

First some remarks on your code:

while(!soubor.eof())
{
  getline(soubor,radka);
  if(soubor.eof()) break;
.
.
.

can be replaced by:

while(getline(soubor,radka))
{
.
.
.

and while (pch != NULL) is actually the same as while (pch) :P

Is the matrix always of the same dimension?

tux4life 2,072 Postaholic

If you program in assembler, knowledge of a high-level/middle-level programming language is already assumed before you even start learning assembly, and you don't know how a simple loop works in Java? :P
If your question is how to do this in assembly, you should have posted/started this thread in the assembly forum :)

BTW, Which loop are you talking about? In Java you've more than one loop: for, while, do-while ; examples:

/* This loop executes if condition is (evaluated to) true*/
while(condition) {
    // your code here
}
/* This loop will run at least one time, and executes as long as expression is evaluated to true */
do {
    // your code here
} while(expression);
/* This loop will run 10 times */
for(i=0; i<=10; i++) {
    // your code here
}
tux4life 2,072 Postaholic

You can use a struct in practically (this means: in most cases, but not always) the same way as a class (because technically structs are classes in C++), consider the following example:

[B]struct[/B] s {
void disp();
s(int num);
[B]private:[/B]
	int n;
};

s::s(int num) {
	n = num;
}

void s::disp() {
	cout << "n = " << n << endl;
}

and it's class equivalent:

[B]class[/B] s {
int n;
[B]public:[/B]
    void disp();
    s(int num);
};

s::s(int num) {
	n = num;
}

void s::disp() {
	cout << "n = " << n << endl;
}

But most of the time the struct is just used as a POD datatype (= Plain Old Data, which means the structs are used like they did before in C: to group related variables)
If you want a class in C++, the preferred way is declaring it by using the class keyword and not by using the struct keyword (however it's possible, as you can see in the above example)
The only difference between a struct and a class is the data's access specifier which is different by default: in a struct all data is made public by default, in a class it's just the opposite: all the data is private by default.

>But I have noticed that initialization is also different.
Use a constructor like in the above example :)

NicAx64 commented: thanks I'm digging you'r post +1
tux4life 2,072 Postaholic

Is reviving a thread like this one really a good idea?
I don't think so :( the first post is at least six years ago :P

Edit:: I just see that the posts are moved to a new thread, so all what's above in this post doesn't apply anymore :)

tux4life 2,072 Postaholic

>I cant write it like #include <Classes.h> , it wont let me to do

That's because Classes.h isn't in your compiler's header files directory, in that case you'll have to put quotes around it instead of < , if you use quotes like this: #include "Classes.h" , you tell your compiler that Classes.h is in the same directory as your other source files :)

tux4life 2,072 Postaholic

If you had compiled this on a new compiler, then this would surely have thrown an error, wouldn't it?

Nope, I can compile it using the newest MinGW compiler :)
(BTW, If there's need for a Borland-style conio implementation for MinGW, you can always find it here)

Regarding to the OP's question:
Check out Narue's page, it's plenty of useful information and code examples, you could also throw a look at this code snippet :)

tux4life 2,072 Postaholic
#ifdef MYHEADER_H
#define MYHEADER_H
//content of the files
#endif

Shouldn't that be #if[B]n[/B]def MYHEADER_H ?

tux4life 2,072 Postaholic

>Should I have to switch to other IDE?
The IDE you're using doesn't define the programming language (C++), so the answer is no :)

tux4life 2,072 Postaholic

If your whole class, including all your class' function declarations looks like this:

class A {
int n;
public:
  A::A(int num);
  void disp_num();
};

A::A(int num) {
    n = num;
}

void disp_num() {
    std::cout << "n = " << n << std::endl;
}

Then you'll have to put the following in the header file:

class A {
int n;
public:
  A::A(int num);
  void disp_num();
};

Edit:: As you classes are spread amongst multiple files, don't forget to compile them all together :)

tux4life 2,072 Postaholic

So I can't do it without that function?

I didn't say that, did I?

tux4life 2,072 Postaholic

> Secondly... how do you return several values with a function?

Just two examples of Salem's explanation:

Using goto :

int a = 0;
while(condition)
{
    while(condition)
    {
         while(condition)
         {
              if(a==5) goto stop;
              a++;
         }
    }
}
stop:
/* Code which has to be executed after the while loop(s) */

Using a state variable (also called a flag):

int a = 0;
bool flag = true;
while(condition && flag)
{
    while(condition && flag)
    {
         while(condition && flag)
         {
              if(a==5) flag=false;
              a++;
         }
    }
}

Edit:: Sorry Salem, I looked over your example (of a state variable) :(