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

You could do it something like this, which increments the pointer by 2 on every loop iteration.

int main()
{
    int array[10][2] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
    int* p = (int *)&array[0][1];
    for(int i = 0; i < 10; i++)
    {
        std::cout << *p << '\n';
        p += 2;
    }
   return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

AFAIK you can not delete attachments. I have wanted to do the same thing but was told that I can't.

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

The default browser is a registry entry. So when ShellExecute() (or some other function) runs it checks the registry to find out what browser to use. If you open another browser on your computer and set it to be the default, then run your program you should find that the new default browser will be used to open google.com.

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

Why a linked list? What about just reading all the values into an array? Then you have everything you need right at your program-tips -- so to speak.

The reason for linked lists is because he doesn't know how many numbers there will be. But that's a mute point if he doesn't know either lists or arrays yet.

To use temp files you would have to read the original file twice. The first time through you calculate the average. Then rewind the file, open two more files for output and begin reading the original. For each number read determine if it is lower or higher than the average. If lower write it out to file1, else if higher write it out to file2. When done, close all three files. Reopen the two temp files and display their contents.

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

Don't you mean you need to use std::string's find() method? e.g.

std::string word = "Hello";
size_t pos = word.find('.', 0);

In the above, just put it in a loop and replace the second parameter to find() with the variable pos that was returned by the previous find. Keep doing that until find returns string::npos.

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

It would be easier to create a linked list (either vector or list header files) of the values when they are read in. Then all you have to do is run through the values in the list.

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

>>*src++;

line 9: remove the star -- you need to increment the pointer, not what the pointer is pointing to src++; line 15: >>*src=&temp; //c2440

You can't do that either. *src is a single character and you can not assign it a pointer to a character array temp. I don't know what you are trying to do with that line.

That entire loop is wrong. It is assigning every other character in src to every other byte in temp array. For odd numbers of i the byte in temp will just contain some junk random stuff which was on the stack then temp was allocated on the stack. I doubt that was your intent.

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

Is "list1" the actual file name? No file extension such as "list1.txt"? And is that file in the current working directory (where the program is being executed)?

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

move line 26 down outside the loop to line 30. Its not necessary to calculate the average every time a number of read. Do it just once, after all numbers have been read, summed and counted.

Your program may do nothing at all if the file can not be opened. Add some code to check that

inData.open(filename);
if( !inData.is_open() )
{
   cout << "Failed to open the file " << filename << '\n';
   return 1;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

All MS-Windows computers have IE -- at least in USA. I've heard there have been some lawsuits about that around the world but I don't know the outcome. HINSTANCE hInstance = ShellExecute(NULL, "open", "www.google.com", NULL, NULL, SW_SHOW); The above will use the default browser, whatever that is.

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

we've (the students) have already worked on compiler and interpreter design prior to this, which I haven't yet. So with that knowledge there is a chance I may need to drop the class because of this

I'm surprised your university even let you register for that class without the prerequisits.

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

In Intel based 32-bit programs the .data and .bss are really in the same segment. In fact, 32-bit (and 64-bit) programs do not use segments at all. Everything, including both code and data, are in the same segment because the compilers use the flat memory model. Compilers for other processors may or may not do it differently.

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

>>f(str[count]>'96' && str[count]<'123')

Use your head a little -- In C language you don't put ' around numeric values and you can not compare a single character to a string.

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

The questions depend on the platform. Here is a wiki article

The return value on Intel based computers is normally stored in the eax register then after the function returns the value is copied to some variable.

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

>>I'm also sure I read somewhere that you can't pass a class as a function argument.

You must have misread it. The class in a is a new instance of the class while the class in b is the same instance. In a the class is passes by value, meaning that the compiler duplicated it and gives it another this pointer.

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

Look carefully -- the function prototype says the first parameter is const but the actual function does not. They have to be the same.

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

if(((int)str[count]>=65 && (int)str[count]<=90) || ((int)str[count]>=97 && (int)str[count]<=122))

it would make more sense like this so that you don't have to think about what the decimal values for 'A' and 'a' are. You are trying to find out if the character is A-Z or a-z, not 65-90.

if( (str[count]>='A' && str[count]<='Z') || (str[count]>='a' && str[count]<='z') )

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

line 9. Might make more sense to calculate the length of both the source and destination strings, then check if their sum is less than sizeDest variable.

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

>>but my laptop is 64bit and the os is also 64bit so i dnt have a proper compiler.

Like I told you before you can use any 32-bit compiler on your laptop. You don't have to have a 64-bit compiler. Just download one of the free compilers either code::blocks with MinGW or VC++ 2008 Express. Not having a compiler is a hell of a poor excuse.

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

You probably didn't put a space or '\n' after displaying dir1 so they were shown together

cout << dir1 << '\n' << dir2 << '\n';

and still I'm getting "infinite loop" after using your solution.!!

Post your revised program that contains the change I suggested

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

Nice work :) Its just as unsafe as the original.

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

See post #7 on this thread

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

>>The truth of the matter was that they returned to school as they didn't want to enter the jobs market.

Maybe they should be taught a job marketable skill instead of college prep skills. Instead of chemistry teach them auto repair, iron working, welding, woodworking etc. They might get more interested in school if they can see that they will learn something useful.

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

>>Dragon, you have a condescending tongue that betrays you.

Tough love isn't always pleasant. Do your homework -- study the subjects and you will learn a great deal more than what you get here. What you got from me ain't nothing. Go to ProgrammingForums.org if you want to get a tongue lashing.

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

what you want in C is FILE structure and associated functions found in stdio.h

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

If you are going to use std::string then you have to learn to read all about what that class can do instead of being spoon-fed on some forum. google for std::string and you will find a list that tells you how to use it.

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

Ohhh that much better :)

Line 22: is that the one with perror()? I don't see anything wrong with it.

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

If you want spaces in the name then you will have to use getline(), not the >> operator.

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

>>If so, how do I fix it?

The same way I would -- use your compiler's debugger and step through the program one line at a time so that you can easily see what its doing.

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

It would have been a lot better to have posted the actual code in code tags to preserve the program's format, such as tabs and spaces. I won't bother reading code that isn't at least formatted a little bit.

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

toss out that old 16-bit compiler and get a modern one. Either of the two I posted or some others too. Old compilers don't work well, or not at all, on Windows 7.

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

You don't need a 64-bit compiler for 64-bit operating systems (unless of course you want the compiler to generate 64-bit code). 32-bit compilers work great. I have 64-bit Windows 7 and use vc++ 2008 Express and Code::Blocks with MinGW. Both both without a problem.

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

>>cabins[L][R][C] != 'X';
Is array cabins an array of booleans? The above will set the array element to either 0 or 1, depending on whether it is equal to 'X' or not.

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

dev-c++ is dead and buried. You can't even download it any more, and the web site has been taken down.

Ditch it and get Code::Blocks with MinGW. AFAIK it won't do Windows Forms either.

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

>>Do you have any idea what is wrong with these errors?

Nope. You need to post the errors and tell us which lines they occur on.

I can see one problem without using a compiler. Its line 25. I'll let you figure out what is wrong with that line.

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

<oops! wrong thread, sorry.>

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

Look at the first error, fix that and several others will probably disappear the next time you compile it. For example vc++ 2008 express complained about line 18. Well, the actual problem is on the line above it -- line 16. Look carefully and you will see that it is missing the semicolon. Fix that then recompile. Then fix the next error.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
int i;
   while ( i <= pow2 ) 
   {
      result *= pow1;
      i++;
   }

In the above code, what is the initial value of variable i?

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

If the compiler will generate the proper machine codes and the linker will produce the proper addresses then yes it will produce executable code....The only remaining obstacle is wrapping the executable code in a format recognized by the operating system...

Isn't that the job of the linker?

The program doesn't have to be compiled on the target operating system. There are cross-compilers which run on one os but compiles and links code for another os. I know of at least one os where there are no C compilers available, so the programmer's only choice is to write assembly code.

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

>>When and why we need to use fflush exactly?
Depends on the operating system. When writing to the screen (MS-Windows) I never use fflush() because MS-Windows seems to write immediately. I have seen the problem on *nix computers where it was necessary even after putting '\n' in the output stream.

When to do it? You won't have to put it after every printf() statement, you can delay callinf fflush() until after all printf() statements but before any input statements. Lets say you want to display a menu that has 10 printf() statements. Just put the fflush() after the last printf().

For disk file streams call fflush() after all writing has been done. Its not necessary to call fflush() before the file is closed because fclose() will do that anyway.

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

variable b is declared twice. Remove the declaration on line 11. And it should be size_t, not int

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

Not that I know of.

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

write a recursive function to do it. But don't make the two arrays very large because recursion takes up a lot of stack space.

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

link But that's all I know about it.

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

>>if ( bad = true )

You need to use the boolean operator == instead of the assignment operator =. That is a common error made by people coming from other languages such as VB which use = to be either assignment of boolean.

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

google for sort algorithms, there are several of them but the one you posted is not one of them. The easiest to code is the bubble sort.

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

First time I've heard that www.bloodshed.net no longer exists. Makes sense since that has been a dead IDE for several years now. Forget Dev-C++ and get Code::Blocks with MinGW compiler.


>>and i cant find a help file to look up simple operators.
Dev-C++ isn't needed for that. Just learn to use google