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

Wrong! All I need is the code and perhaps the text file he's using, then I can compile it from within my IDE. .

I agree you can do it, but when there are multiple files its just easier to post the .zip file. You can choose to download or not. A virus scanner will take care of any viruses that the zip file may contain. And it saves a lot of time copy the code from the browser and pasting it into my own project.

[edit]the files speterson posted have the same problem(s) as the zip file you dislike so much.[/edit]

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

>> srand((unsigned) time(&t));
you don't need the argument to time()

srand((unsigned) time(NULL));

>>#if defined(_MSC_VER)
delete the above line and the corresponding #endif. time functions and rand functions are both standard c/c++ library functions that are supported by most c or c++ compilers.

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

here is how to enter the characters of a number as a string and convert to float. If this code is too much for you then you should probably shelve your project for awhile and concentrate on learning c++.

#include <string>
#include <strstream>
#include <iostream>
using namespace std;

int main()
{
    string input;
    float num;
    strstream str;

    cout << "Enter a number...";
    cin >> input;
    str << input;
    str >> num;
    cout << "num = " << num << "\n";

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

Hmm, I am supposed to use a two dimensional array, which of course I'm not sure how to do except i need to use ascii maybe?

here is the 2d character array. define MAXTITLES and MAXTITLELENGTH whatever value you wish.

char titles[MAXTITLES][MAXTITLELENGTH];

after opening the file, enter a loop and read each line until end-of-file. If song titles contain spaces you will have to use infile.getline(). Something like this:

char titles[MAXTITLES][MAXTITLELENGTH];
char name[MAXTITLELENGTH];
int nTitle = 0;
while( infile.getline(name,MAXTITLELENGTH))
{
   strcpy(titles[nTitle++],name);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>It still works, why? Explain.
Is that a rhethorical question? you already answered it.

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

>Also, always make sure your main() returns a 0.

Why? Pray tell?

It is standard convention throughout the IT industry for programs to return 0 when it exits normally, or some other value to indicate an error occurred. This allows other programs to check the status of the program and take appropriate action if necessary.

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

After a little testing I got it (GetFileSize) to work when coded as inline assembly. After opening a file it is not necessary to move the file pointer to the beginning of the file because that is the default behavior unless stated otherwise in MSDN.

;=================== open file ================;
        push 0
        push FILE_ATTRIBUTE_NORMAL
        Push OPEN_EXISTING
        push 0
        push FILE_SHARE_READ
        Push GENERIC_READ
        push offset inputFile
        call dword ptr CreateFileA
        mov iFile, eax
;=================== set write head at 0 ================;
        Push FILE_BEGIN
        push 0
        push 0
        Push [iFile]
        call dword ptr SetFilePointer

        Push 0
        Push iFile
        Call dword ptr GetFileSize
        mov File,eax

;=================== close file ================;
        push iFile
        call dword ptr CloseHandle
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

By the way, I notice you aren't clearing the stack after each call. In C the called procedure won't do it for you, so if you push n bytes before the call, you have got to pop them again afterwards.

win32 api functions use __stdcall calling convention -- the called functions clean up the stack before returning. So stack cleanup is not necessary in his asm program.

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

your program does not verify that CreateFile() returned an invalid file handle. It should check that the value stored in eax is greater than two (0, 1 and 2 are reserved handles).

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

you are not finished with the wages() function yet. The whole idea of that function is to populate the money[] array with the salary. After calculating salary you need to add it to the ith element of the money[] array. you will have to add an integer counter to keep track of the current row number in the array.

>>while(sales >= 0);
also add verification that the counter value (see above) does not exceed the number or rows in the array so that you can't add more sales numbers than there is room in the array.


>>for ( index = 0; index < salary; index++ ) {

No! not salary but the number of rows in the dollars array. I would add another parameter to the function that indicates the number of rows in the array because without it that function has no clue what it is.

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

are you using Windows operating system? If yes, your use account needs to have administrative privileges.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
invoke ExitProcess,eax
        invoke PostQuitMessage,0

I think you should delete the call to ExitProcess because it will not give the windows application a chance to do proper cleanup. I believe ExitProcess is intended only for console programs.

>>But there's something wrong in that GetFileSize area
I don't see your program calling GetFileSize() ????

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

>>Is it possible to find the no. of elements in an array after inserting without counting while insertion

depends. For statically allocated arrays see andor's response. Otherwise, it is not possible because c arrays do not keep that kind of information.

If you are using C arrays and the array is dynamuically allocated then you should have an integer that contains the current size of C arrays.

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

Can you post just the code here. I don't like downloading zip files in case they contains viruses and other known nasties.:cheesy:

in this case, no. a zip file is better because it contains lots of files and some of them contain binary information. Besides, you should always be running a virus scanner which will catch viruses.

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

OMG: do you really write your code all on one line like that!:eek: I'll bet your teacher is very proud of your coding style.

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

two problems I can see without even compiling it.

1. main() should return an integer. I know it returns 0 if no return is specified, but you should expeclitly return a value anyway.

system("pause");
     }
     return 0;

2. Above is not inside any function.

>>#define PI 3.14159
you should declare this as a const. defines are fround upon in c++ programs.

const float PI = 3.14159;

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

>>samples of connecting to mdb file, but there are so complicated...
There is nothing simple about working with databases. If you find it too complex then maybe you are not yet ready for it.

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

>> Typo's are one thing. Completely failing to grasp the concept of proper spelling and grammar, is just plain dumb.

English is not the native language of many posters, so I rarly, if ever, criticize anyone for their use of English unless they use abbreviations such as y for you.

Sorry about not answering your question -- I don't know. :confused:

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

here is something just off the top of my head -- untested and uncompiled.

int isvowel(char c)
{
   if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
          return TRUE;
   return FALSE;
}

...
...
if( string[ctr] == 'y' )
{
   if( !isvowel(strin[ctr-1]) && !isvowel(strin[ctr+1]) 
   {
          // y is a vowel
   }
}

your program also needs to verify that (ctr-1) >= 0 && (ctr+1) <= length of the string.

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

15. never plan/design a new program, just start typing and see where it will take you.

16. write programs in assembly language. higher-level languages are for wimps.

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

what operating system? Creating threads is different for each os.

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

No one has even said ANYTHING about disabling the start menu...In the mean time I have found out how to not allow a user to click it, but they can still use the windows key (on the keyboard to access it...I have already been accused of trying to make viruses on other sites, but I am actually trying to lock my computer from unwanted access (little brothers, sisters) So if anyone could tell me how to do it that would be wonderful.

The first place to begin your research is at Microsoft. There appears to be several threads about that.

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

>> what is the use of the operator "&" in the mutator
The class is declaring the operator[] which returns a reference to one of the elements of an array. By doing this you can use it in the left-hand side of an expression. You didn't post class OrderName, so lets just assume it has an int member that you want to assign a value of 5.

Order o;
o[1].someVariable = 5;

In the above example, the class'es [] operator will be invoked.

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

All dlls must have DllMain(). This is the code generated by M$ VC++ compiler when creating a dll project.

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
    return TRUE;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Hmm, I always thought the last number added was ' j ' (Don't know if it's called j in US/England). j^2 = -1

that is an imagenary number. I think it is represented by the letter 'i', not 'j'. I flunked biology so I don't really know:mrgreen:

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

why don't you join their mailing list and ask them?

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

Would those functions protect from integer overflows/underflows

yes -- did you read those links you posted?

AND format string attacks?

:?: are we playing packman game here?

2. What about strings?
Does a simple use of fgets protect from buffer overflows AND format string attacks?

buffer overflows -- yes. Again, I don't know what a "string attack" is.

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

>>but I unfortunately only have 40 minutes until it is due
unfortunately for you the time expired 6 hours ago. Lesson learned: don't wait until the last minute to get help.

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

undefined identifier means a variable is being used before it is declared. If it compiles ok in debug mode and not release mode then there is probably a conditiional compile statement somewhere, something like this:

#ifdef _DEBUG
int x;
#endif

I would compile again for debug, move the cursor to the line and symbol name where the error uccurs, right click with mouse, then select "Go to definition" from the popup menu. VC++ IDE will move the cursor to the place where the symbol is defined. There you will probably find a conditional compile statement similar to the one I posted above.

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

>>PLEASE HELP ME!!!!!

help you do what? does your program compile ? (hint: no it does not).
what errors does your compiler produce?

if(txt.find(a)!=txt.end()) {  
cout<<
}

Above is incomplete statement.

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

>> double Points; //Point's Scored
why are you using double here? Can value of Points have a fractional part (I doubt it)? I think you would be better off using either int or long.


>> cin.getline(players.name;
that should be like this:
cin.getline(players.name, SIZE);

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

that error means you have not coded the function. compare your program with the template your teacher gave you and you will see your code is missing that function.

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

1. you need a semicolon after the declaraction of salary

2. count the number of closing braces in that function. You have one too many.

>>I think that's my stress level going up
Yup, that happens to all of us. When you get stressed out just get up and go have a cup of coffee or something. DO NOT drink alcohol -- it does more harm than good.

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

did you try google ?

I don't use a cellphone so I have no idea where to get them.

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

that link you posted has a lot of tutorials. Just do them and learn.

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

>>Is my english all that good? :P No..I'm not American..I'm Romanian
yes -- your English is excellent.

>>My post wast not about the search algoritm itself, it was about how to do it in ASM.
you start out by just doing it. do you already know 80x88 assembly ? If you do then writing that program should be a piece of cake. Sorry, but I'm not gonig to write an asm version of the program.

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

All I can get from that page is that "the politician" helped the internet along..good for him...but that doesn't mean that he invented it..
No one really invented th internet...

You are apparently not an American. That was all just a big joke here a few years ago. Al Gore didn't really mean it -- it was a slip of the tounge and everyone laughed at him about it.


About the code..I just can't believe that I'll need a few thousand lines of ASM code to do a recursive file search...

Anyone..any ideeas?

Cheers

You probably won't need quite that much code. I already mentioned you convert a C program to assembly. I have already posted two such code snippets

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

>>I tried writing some code for this, but am having way to many issues

please post code, and use code tags as described in the links in my signature below.

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

>>// main will not require any modification

you did not follow instructions. put main() back the way it was and add your code in the wages() function.

>> for( int i = 0; i < 3; ++i )
There is no limit to the number of salaries you can enter. So you are using the wrong kind of loop. I suggest using a do-while loop, something like this:

do
{
        cout << "Enter employee gross sales ( -1 to end )" << endl;
        cin >> sales;
} while(sales >= 0);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I always thought the internet was "invented" by the american military in the 80's..I think I was wrong

Not according to this :mrgreen:

The code you posted is not a complete, self-sutaining, program. It must be linked with a normal C windows program. It appears the author just used a C program, had the compiler print the assembly code, then twik it to suit himself. It might be fun to do and instructional, but not much practical value to it other than learning how c programs work.

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

>>Lookin forward to some 'ingenius' reply
Search google for the implementation in C, then convert it to assembly. Also google for "Quick Sort RECURSIVELY in assembly language" and you might find what you want.

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

why don't you just buy the book?

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

>>I'm actually surprised you diidn't know about that page..it's among the first I read when searching for asm tutorials...

I have not written assembly for the past 15 or so years, before a certain politician (no names please) invented the internet.

I do use the "FindFirstFile" API call, and I guess it's the same thing in asm..but I was curious how much harder would be to code this in ASM..
Cheers

Take the number of lines you have in your C code and multiply by 100. :cheesy: Or, more accurately, have your compiler generate assembly listing, then compare the two.

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

>I'm using the 2005 version of C++

You do realise that doesn't make any sense. Also you've neglected to tell us what operating system you're on. Although "my documents" sounds pretty much like windoze.

It makes perfectly good sense to me, learn to think outside the box:mrgreen: -- Visual C++ 2005 and of course the os is MS-Windows.

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

Do the assignment one step at a time and it will be a lot easier. If you try to do it all at once you might wind up just getting more confused.

Start with function wages(). You know that you have to have a prompt "Enter employee gross sales ( -1 to end )" inside that while loop, and somehow you have to allow the user to type in a number into the double variable sales, which is already defined in the function. Once you get that you need to calculate the commission with is 9% of the sales. That's simple 2nd or 3d grade math -- employee commission is $200.00 plus (sales * commissionRate).

Get that all working then come back for more questions/answers.

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

Thanks for that link -- seems to have a lot of good information. I'd suggest you work through the tutorials they have and by the time you get done with them you might know how to do the file i/o you are asking about.

My guess is that you will need to call the win32 api functions FindFirstFile() and FindNextFile() to get a list of all the files. I don't know the details about the assembly code they use, but they are more than likely calling some kernel-level functions.

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

Check out the win32 api functions FindFirstFile() and FindNextFile(). They allow the program to iterate through all the files and directories in a folder. The compiler you are using will work well. When you create a new project you want to create a win32 console program, unless you want to add windows gui too, such as dialog boxes.

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

thanks so much for your help
but I know how to declares the character already .. the problem is how to get the program working :(

Where is your code? What have you tried? People here are not mind readers, so you need to post YOUR code. And please use code tags as described in the links in my signature.

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

1st: there is no such thing as "win32 asm". win32 is an operating system that runs on top of the hardware Intell and Intell-look-alike chips. what you really mean I presume is 80x88 and Pentium assembly code.

Yes it can be done in assembly, afterall all C compilers compile everything down to assembly code. But what you want to do with modern 32-bit programs that run in protected mode is just a lot easier to do with a C or C++ compiler. An assembly program is not allowed to make direct interrupt calls in 32-bit protected-mode programs. You can do that in 16-bit real-mode programs, but the program will not be able to process all the space on today's huge hard drives -- I think they are limited to 2 gig drives/partitions.

As for speed -- just because its hand-writen assembly code doesn't mean it will be faster than the code generated by a good, modern optimizing C/C++ compiler. The speed of todays RAM -- mine is 2.5 Gz -- and new compilers have made hand-writing assembly almost a thing of the past.

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

1st: please use code tags when posting code. If you don't know how to do that you can read the links in my signature.

2nd. Many compilers will produce assembly language printouts of the c code. Check your c compiler to see if it has options to do that. If not, I don't know MIPS assembly, so I can't help you.