Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Why would you want to write an address to a text file? It isn't useful for anything after the program that gets the address is finished.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I'ts been almost two weeks now since the original post, so here is my solution if anyone is interested

Note that every other line that is printed is either a consonants (abcdef ...) or a vowel (aeiou).

#include <stdio.h>

int main()
{
    int seq = 0;
    int i;
    for(i = 1; i < 6; i++, seq++)
    {
        if( (seq % 2) != 0)
        {
            // print series of consonants
            char c = 'a';
            for(int j = 0; j < i; j++)
            {
                putchar(c);
                ++c;  // increment the letter
            }
            putchar('\n');
        }
        else
        {
            // print a series of vowels.  Ignore the fact that y can sometimes
            // be a vowel.
            for(int j = 0; j < i; j++)
            {
                char c = 'z';
                switch(j)
                {
                    case 0: c = 'a'; break; 
                    case 1: c = 'e'; break;
                    case 2: c = 'i'; break;
                    case 3: c = 'o'; break;
                    case 4: c = 'u'; break;
                }
                putchar(c);
            }
            putchar('\n');

        }
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Well, we do, and we should so that we don't lose track of threads we have poted in.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I wouldn't say that. I have arguments with my wife too, but we're still best of friends.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

In WinProc() cature the WM_RBUTONDOWN event. lparam contains the mouse coordinates.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I must admit that I've started reading the articles a little more since this thread was started. I hadn't paid much attention to them before.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Very intereting :)

>> and he is confident in Intel's ability to generate plenty more cash.
Who said we are in a recession? Apparently Intel isn't. I hope they are putting all that cash to good work that create new jobs instead of just putting it under their mattress for a rainy day.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

When you move a thread here in DaniWeb Community Feedback I wish the mods would leave no redirect links. Its rather annoying to see all those moved threads, they just clutter up the list with useless links.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

First declare a structure that contains elments for street address, suburb, and price.

Then useing ifstream open and read the file.

I could write the code for you, but I won't. I wouldn't want to deprive you of the joy of doing that yourself :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You can get handles to all windows, which ones would have .mpp files I don't know. See win32 api function EumWindows()

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What you want is a character array char buffer[255]; That declares an array of 255 characters. c++ also has a std::string class, but you can not use that with SqLite database.

You have to be careful about allocating new memory in a DLL. Memory allocated in a dll with new or malloc() must also be destroyed in that same dll. (std::string allocates memory like that) So you would need to declare that function like this: char* DLL_EXPORT GetDirectory(const char* Subdomain, char* returnbuf) where returnbuf (or whatever you want to call it) is a character array allocated by the calling function and used by GetDirectory() to store the string it needs to return. The return value of that function is just returnbuf, or NULL if an error occurs. You could also make the return value just a bool, indicating either success or failure.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> It should be a multiple of 4 bytes.
Depends on the compiler and how it aligns the structure object. You can change the alignment with most modern compilers so that it is 1, 2, 4, 8, 16, 32 etc aligned. The default alignment is compiler dependent too.

mrnutty commented: Thanks for the info. +5
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Well, you used code tags, but the formatting is still horrible. I you can't bothe to indent your program properly then I won't bother to read it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

sleep() takes whole integers. You can't pass 0.99 and expect it to do anything because 0.99 is converted to just 0. If you want to sleep less than one second then use nanosleep()

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Not specific to MFC. Just add .5 and take the integer part

int main()
{
    float f = 1.67F;
    f += 0.5F;
    f = float((int)f);
    std::cout << f << '\n';
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Q3: The author may be wrong. Wouldn't be the first time wrong info was printed in a book.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Depends on how the dates are formatted. If they are in YYYYMMDD format then you can simply use strcmp()

char *date1 = "2010/01/01";
char *date2 = "2010/06/05";

int n = stramp(date1,date2);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

1. Learn to use code tags. The code you posted is almost impossible to read without them.

2. What is the problem with your program? What does it not do that you want it to do? Are there any compiler errors? If yes, then what are thy?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I would get the input data as a string, then check each character to see that it is a numeric digit 0-9 or a . for floats (and there can be only one dot in the string). If it passes that test then convert the string to a float.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It could mean several things. Most likely your program has mismatched { and } braces.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The file is probably not in the current directory. either use getline() so that you can enter the complete path to the file, or move the file into the current working directory, which is where the *.cpp file is located. Also make sure you spell the file name correctly -- I like to just hard code them for testing purposes.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Q1: That doesn't work because what you have to do is extract each of the digits from an integer. If you enter 1234 then you have to count each digit 1, 2, 3, and 4.

Use the % (mod) operator and / to do that. This isn't the complete code -- you will have to put it in a loop.

int x = 1234;
int odd = 0, even = 0;
int n;

n = x % 10;
if( n % 2 == 0)
   even++;
else
   odd++;
x /= 10;

Q2: You know that there are 60 seconds in a minute, and 60 minutes in an hour, and 24 hours in a day. If you have 1000 seconds then its simple 5th grade math how to convert it to days, hours, minutes and seconds. If you don't know how to do it then you need to take a remedial math course.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Did you read this?, especially InsertMenuItem()

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

7687 can't be right because if you try to unencrypt it one of the digits will be a negative number

7 6 8 7
subtract 7 from each digit
0 -1 1 0


If you try to add 7777 to number before doing anything, then the result is 7868.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

then just use strcpy() -- it will put the null character at the end for you.

char id[6];
strcpy(id, "Hello");
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Oops! my mistake, I was thinking we were in the c++ forum. Sorr for that. But the concept is the same.

#include <stdio.h>

int main()
{
   char id[7];
   FILE* fp = fopen("filename.txt", "r");
   fgets(id, sizeof(id), fp); // read the string
   // fgets() puts '\n' at the end so we need to remove it
   if( id[strlen(id)-1] == '\n')
       id[strlen(id)-1] = '\0';
   printf("%s\n", id);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

No. That will not work. If you are not sure about something then try it out on your own compiler before posting here.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Read it from the keyboard, a data file, socket stream, or what?
From a data file. ifstream will put the null terminating character at the end for you. You don't have to do anything with that.

#include <fstream>
#include <iostream>
using std::ifstream;
using std::cout;

int main()
{
   ifstream in("filename.txt");
   if( in.is_open() )
   {
      char id[6];
      in >> id;  // read the ID from a data file.
      cout << id << '\n';
   }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

encryptnum = (dig3 * 1000) + (dig4 * 100) + (dig1 * 10)+(dig2) + 7777 ;

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> number%10 = dig1;

That is backwards. dig1 = number % 10;

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Read the string "hello" include the NULL character in the end of string.

What exactly does that mean? Read it from where?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>while(choice=1||2||3||4||5){

Can't do it like that while( choice >= 1 && choice <= 5)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Your program will get a runtime error because vector entity doesn't have any elements, so all those assignments in lines 9-15 will fail.

>>if(strcmp((*tokens), ',')

If you only want to compare two single characters to see if they are the same then why use strcmp()?? Just use == operator to compare them

for(i=0; i<tokens->size(); i++)
    {
        for(j=0; j<7; j++)
        {
            matrix.push_back(vector <char*>());
            if(strcmp((*tokens)[i], entity[j])==0)
                do{
                    i++;
                    if( *tokens->at(i) == ',' || *tokens->at(i) == ';')
                         strcpy(temp, tokens->at(i));
                }while(*tokens->at(i) == ';');
        }        
    }
nirali7 commented: you're awesome!!! +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The NULL character is '\0', or just simply 0. Use while loop to check each character in the string.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You are only a year too late :) He needed it almost a year ago.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Also suggest you get a modern free compiler such as Code::Blocks and VC++ 2010 Express.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You obviously need to read some c++ tutorials. iostream.h is long obsolete and should no longer be used. Current c++ header files do not have .h extension <string> and <iostream>

<string> is the header file that declares the c++ std::string class
<iostream> declares std::cin, std::cout, etc.

There are quite a few header files, and you will learn them by reading books and/or online tutorials. Here are a few ebooks you can download for free.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Its posted in the first post to this thread -- way over on Page 1.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You can not use graphics.h with that compiler. If you want to draw curves then you will have to bite the bullet and learn win32 api programming, or learn MFC.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The first line just declares a variable of type std::string

The second line causes all keyboard input up to the '\n' (carriage return) to be sent to the string object. So if you typed "Hello World" <Return key> then the string subChoice would contain "Hello World".

Copy and paste this into your compiler's editor, compile it, and run it to see for yourself what it does

#include <iostream>
#include <string>

int main()
{
   std::string subChoice;
   std::cout << "Enter some text\n";
   std::getline(std::cin, subChoice);
   std::cout << "You entered \"" << subChoice << "\"\n";
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Your program is also inconcistent in the way it declares std namespace. If you don't use using namespact std; or using std::vector; then you have to preface every instance of vector with std::, such as std::vector< std::vector< std::string> > something; As for the parameter tokens -- unless that is an array of std::vector objects, then it would be better to dealred it as a reference instead of a pointer -- std::vector<std::string>& tokens) . That would remove the ambiguity between passing a reference to a single vector object or passing an array of vector objects. Declaring it as a pointer we don't know which one you meant without seeing the function that calld it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You are correct, I have never used Xbox Live. And from what you just posted I don't really want to :) I now understand why you called them idots -- maybe you were right afterall.

Glass_Joe commented: I like you +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You mean the + operator?

class MyClass
{
private:
   int x;
public:
   MyClass() {x = 0;}
   MyClass operator+(int x)
   {
      MyClass n = *this;
      n.x = n.x + x;
      return n;
   }
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

just delete both of those folders. The IDE will re-create them. And don't forget to remove the precompiled header file -- you will easily see it because of its size.

Sorry, but I don't have that version of the compoiler/IDE.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Is there a reason you are using strings instead of simple integers? It would be a lot simpler to manipulate an integer then convert it to a string for display purposes.

#include <stdio.h>
#include <string.h>

int main ()
{
    int x = 39989;
    char result[80];
    for(int i = 0; i < 11; i++)
    {
        x = (++x) % 40000;
        sprintf(result,"%d", x);
        printf("%s\n", result);
    }
    return 0;
}

[edit]
>>p = (p++) % 10; // doesn't work

Use pre-increment
x = (++x) % 10; // works
[/edit]

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I see that is an MFC program. What version of the Microsoft compiler are you using? If you want anyone to test out your program you need to zip up the entire project directory and upload it here (us the Advanced Editor options to do that). But first delete all the compiler-generated files, such as *.obj and *.pch.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

This wiki article tells you how to derive the gcd. Pay close attention to the section about the Euclidean algorithm.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It's Pig Latin, not piglakin. Read this wiki article to see how to convert English words into pig latin. It will not give you the c/c++ code, but will show you what you have to do.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>It should sum all the even numbers between those two values

That's simple 5th grade (or less) math. If you have problems comprehending that requirement then you need to sharpen up your basic math skills.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you have to use a for loop

for(int i = first+1; i < last; i++)
{
   if( (i%2) == 0)
   {
      sum += i;
   }
}