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

>>I did was to Initialize char * string1 = "longer than string2" and evrything else the same and it didnt work either
I didn't work because you can't change string literals, which is what you attempted to do. But you could have done it like this: char string1[] = "longer than string2" , which will put the text in writeable memory.

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

You are attempting to stuff 3 bytes (string2) into a character array that is only 1 byte (string1). Try this:

int main()
{  

char string1[4] = {0}
char * string2 = "EL";

StrCpy(string1, string2);
//cout << string1; //must output EL
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Since you are not working on a homework problem, I found it a little interesting to code the first problem. There are many ways to program it, and as long as they all have the same result, each method if probably as correct as any other. Here's my effort. It only uses c++ for cout.

#include <iostream>
using std::cout;

struct val
{
    int value;
    int pos;
    int count;
};

int main()
{
    char str[] = "12 23 23 34 34 34 455";
    struct val* iarray = NULL;
    int arysize = 0;
    int pos = 0;
    int nm;
    int i;
    int n;
    int found = 0;
    int len = strlen(str);
    int counter = 0;
    // convert the string of numbers into an array of struct val
    // The array will contain only one entry for any given number,
    // along with the position at which the first value starts in the
    // string and the count of the number of times the number appears
    // in the string.  This algorithm will not work correctly if the sequence
    // of the same number appears more than once in the struct, such as 
    // "1 2 3 3 4 5 2 2 3 3";
    for(i = 0; i < len; )
    {
        // skip white space
        while( str[i] && isspace(str[i]) )
        {
            ++i;
            ++pos;
        }
        // convert ascii to int
        nm = 0;
        while(str[i] && isdigit(str[i]) )
        {
            nm = nm * 10 + str[i] - '0';
            ++i;
        }
        // check of …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It's late here and I'm very likely to be forgetting something - someone please do correct me in that case :P

EDIT: I could be almost asleep and hence not perfectly able to understand but


is that right? I mean isn't it 3rd position too ?

1 2 2 3 3 3 4  <-- string
^ ^ ^ ^ ^ ^ ^
0 1 2 3 4 5 6  <-- positions
      ^

I apologize if I have misunderstood

We have no precise/exact definition of a "position". I was counting white-space (spaces and tabs) as positions.

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

mrboolf: is that PASCAL code?

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

There is no such macro declared in windows.h. Maybe you mean SW_MAXIMIZE ? If yes, then look in WinUser.h header file

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

Can you use the functions in time.h? If you can, then just fill in a struct tm and call mktime() to calculate tomarrow

#include <time.h>
...
int main()
{
    int m = 11; // November
    int y = 2008;
    int d = 2;

   struct tm tm;
   // clear all members of the structure
   memset(&tm,0,sizeof(struct tm));

   tm.tm_year = y-1900;
   tm.tm_mon = m-1;
   tm.tm_day = d;
   // increment tomarrow
   tm.tm_mday++;
   mktime(&tm);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

use Regedit program and look in HKEY_LOCAL_MACHINE\\Hardware\\Devicemap\\Video
That's where its at on Vista.

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

First, do you know how to read a file in C language? If not, here's a tutorial

The position in problem #1 can be interpreted a couple ways depending on how the file is formatted. If all the numbers are on one long string, then the position will be the character position on that line, for example: "1 2 2 3 3 3 4" the position will be 6 because the first 3 is in the 6th character position. If on separate lines

1
2
2
3
3
3
4

Then the position will be 3 because the first 3 in on the 3d line.

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

How to search for something in the Code Snippets boards ??? The "Search In Forums" listbox doesn't include tutorials or code snippets. If I want to find something in C code snippes related to "FILE", the only way to do it is to read each and every post in those tutorials. Would be useful to have a quick way to search them.

Nick Evan commented: good idea! +12
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Of course. I already mentioned you should use the rand() function. Lets say the string is "Hello World"

char str[] = "Hello World";
int len = strlen(str); // length of the string
int x = rand() % len; // get a number between 0 and length of string
char c = str[x]; // get the character

The above is a little long winded, but illustrates how to do it.

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

Maybe that's the way to go :) But I don't think I'll try doing that with my computer.

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

Is MSXML installed on your computer? You have to download and install it from here.

And make sure you read all of this article

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

If the hardware is too old then Vista won't even install. Needs to run the Vista Upgrade Advisor before spending money on a new hd to see if he needs a whole new computer.

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

If you are going to buy a new hard drive get the biggest one you can affort because in a couple years it won't be big enough!
A few years ago the first hd I bought was 80 meg and cost about $500.00 USD. I thought it would last forever, but forever turned out to be about 6 months when I filled it up with MS-DOS 6.X os. I have bought several since then and MS-Windows seems to be getting bigger and bigger as hardware gets cheaper.

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

rand() returns a random value between 0 and MAX_RAND.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
void conversion (int size, char lines [Max_Lines][Max_Size], char alphabet[27] = "abcdefghijklmnopqrstuvwxyz", int alphacount [27] = 0);
void displayTable (int alphacount [27] = 0, char alphabet[27] = "abcdefghijklmnopqrstuvwxyz");

Remove the { and } around the default parameters. That will cause the int array to be NULL pointers if the calling function doesn't supply the array. For example

int foo(int ary[4] = 0)
{
    if( ary != NULL)
    {
        for(int i = 0; i < 4; i++)
        {
            cout << ary[i] << "\n";
        }
    }
    cout << "All done\n";

    return 1;
}

int main()
{
       foo();
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

This is turning into just a bitching contest, so I'm closing the thread.

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

You don't need iomanip to do that. The macro toupper() will make the conversion for you

char c = 'a';
char upperc = toupper(c);

Now you will have to put something like that in a loop so that the entire line is converted to upper case.

If you are really really smart and know your stuff you can do it like this:

#include <algorithm> 
#include <string>
using namespace std;
...
...
std::string line = "Hello World";
transform(line.begin(), line.end(), line.begin(), toupper);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I am sorry if you feel offended, but all I am saying is that I do not want to waste your time. I am in need of help and I am willing to pay for your time, I dont see where the problem is.

Do we really give a shit? NO. There are many things in life we have to do but don't like to. Learn to deal with it and do the work you are given.

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

There are lots and lots of examples here and other places on the net that show you how to read a file. I know there are also examples in your textbook, if you bothered to read and study it.

std::string line;
ifstream obj1 ("C:\\file1.txt")
while( getline( obj1, line) )
{
    // blabla
}
mrboolf commented: well said, as usual :) +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

where is the code you have started to solve the problems? We will not write it for you. Write it a little bit at a time and your program will soon be written.

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

>>dont know how i can because i dont know the material!!
I'd say you better start by reading the books and other material, and doing the exercises at the end of each chapter. You won't learn how to program is other prople do your work for you. Yes, we will help, but only after you post code to show you are making efforts.

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

There isn't much you can do about overflows, except just discard the bad CString value. It returns INT_MAX because its impossible to put that many digits into an int variable. I'd like to stuff my 100 inch waste into size 36 slacks too, but that's not possible either :)

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

There are a couple approaches in c++ language:

1) if input is in the form of a std::string object, you can use it's find() method to determine if it contains any of the words, example:

std::string input;
cout << "Enter a word\n";
cin >> input;
if( input.find("ONE") != std::npos)
{
    // found it.
}

2) The other way, using standard C style character arrays

char input[20];
cout << "Enter word\n";
cin >> input;
if( strstr(input,"ONE")  != NULL)
{
   // found it
}

Now if course you will have to change the above to check each of the words listed in your assignment, as well as all the other requirements which I did not mention.

And don't forget to include the appropriage header files.

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

>> how do i merge these two

1) Write a c++ program instead of C program.

or

2) Write a c++ stub program that has functions callable from C program and link the two object codes together.

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

that doesn't work if your program does not have a message pump. I've never tried it in a dll but I do know it doesn't work in a standard C/C++ language console program.

You might want to write a small C windows program that tests your dll to see if you can get the dll to work like you want it.

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

I don't see a problem with that code. It is legal and ok for a class to return a string like that.

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

Looks like loadGameFile() is failing to open the file games.txt

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

I don't do linux but I do know it has several different gui apis, such as Motif, so you have to be more specific about which one you are using.

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

>> And halfway through, i tried to compile and run
You need to compile and fix errors a lot sooner than that!

>> void displayGame(list <Game>& myGame);

You have not coded that function.

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

Assuming you are using MS-Windows, you will probably find something in one of these Font and Text Functions.

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

people should more aware about global warming...

We are fully aware of it -- we just don't believe it. Global warming is a natural occurence that has occured many times in the earth's history. Al Gore is just a big joke.

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

look in limits.h to find out the maximum/minimum values of the data types for your compiler.

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

Thx :-)
Is it worth a reputation point?
(gotta pull the plugs when you are new!)

Nope -- sorry but no one gets rep points here in Geek's Lounge.

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

First, the arrays have to be pointers so that they can be allocated at runtime. For example: float *x[2]; float * fx[2], Next, after finding the upper_limit (line 26) you can use malloc to allocate the arrays of the proper size

int i;
for(i = 0; i < 2; i++)
{
    x[i] = malloc(upper_limit * sizeof(float));
    fx[i] = malloc(upper_limit * sizeof(float));
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Thread closed.

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

what is "CHR/2" ? If you need 8 random numbers between the values of 0 and 16, then put them in an array.

start loop
    generate random number between 0 and 16
    first time the number has been generated ?
    no, then go back and generate another number
    yes, add to an array of generated numbers
    if 8 numbers have been generated than exit loop
end of loop

to generate a number between 0 and 15 int x = rand() % 16

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

LOL very good :) That's what he disserves for being so greedy

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

Depends on what you are attempting to do. If you want to see the file contents only after it has been changed by the other program then your only choice is to close the file in your program and reopen it.

If, on the otherhand, you want to see the original contents of the file you have a couple options:

1) After opening the file read the whole thing into memory and work with that.

2) Use some os-specific function to lock the file when it is opened so that other programs can not change it. ON MS-Windows you can use the win32 api fucntion _fsopen()

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

The problem is the way the program opens the file on line 22 of the code you posted. "wb+" will delete the contents of the file if the file already exists. Read about the open flags here.

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

You mean while reading the file there is another program changing it? If that is correct, then all bets are off because the results of your program will be unpredictable. Your program gets the original file probably due to disk cashing -- when the file is opened the program just reads the entire file all at one time then doles it out to your program a little at a time.

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

What an unusual way to sing that song :)

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

what's wrong with a word processor, such as Microsoft Word ?

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

use a pointer and convert each digit to binary. Here's how:

char str[] = "123.456";
char* ptr = str;
float n = (*ptr - '0'); // before the decimal point

float n = (*ptr - '0') / 10; // after the decimal point

Now, what I posted above is not a complete program -- I purposely left out important code that will make it work. You also have to have a couple loops and change 10 to a variable that is incremented by 10 on each loop iteration.

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

Angry German Kid video -- OMG he acts like a spoiled brat! I understand getting angry at a computer, but that is overdoing it. He needs to visit a head shrink.

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

http://www.break.com/index/lanpunch.html

I don't know what this guy is saying, but I'm sure it isn't nice :)

And how about this one too :) :) :)
http://www.break.com/index/treadfall3.html

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

loop is incorrect. Here is how to read until end of file. fgets() returns NULL on end-of-file or some other type of error.

while( fgets(s, MAX_BUFF, file) != NULL)
{


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

I suppose you could make print_reverse() recursive, something like this: (Note: not compiled or tested)

void print_reverse(int i)
{
    if( i < MAX)
        print_reverse(++i);
   cout << st[i] << "\n";
}