Freaky_Chris 299 Master Poster

Firstly NEVER use void main() always int main() (of some variation).

Secondly do you know how functions work?

void selectionSort(int onestudent[], int x);

What is that doing inside your main method?

void selectionSort(student onestudent[] , int listLength);

void selectionSort(student onestudent[], int listLength){
  for (int i = 0 ; i  <= listLength-1 ; i++){
         if(strcmp(onestudent[x].id_number,onestudent[x+1].id_number)> 0){
                 strcpy(temp,onestudent[x]);
                 strcpy(onestudent[x],onestudent[x+1]);
                 strcpy(onestudent[x+1],temp);
         } 
  }
}

Note i also changed the function declaration to student rather than int & variable names changed so they actually matched!

And i used [code=cplusplus] [/code] so formatting is kept. I also re-indented the code for you so it is more re-adble to others, so they can look at you so called selection sort.

Chris

Freaky_Chris 299 Master Poster

Allow me to correct my error

out_file << "\nHello, World\n";
     out_file.close();
Freaky_Chris 299 Master Poster

Can i also point out that those are C functions. If your after the C++ solution it goes something like this

#include <ofstream>
#include <iostream>
using namespace std;

int main(void){
   ofstream out_file;
   out_file.open("example.txt");
   
   if(out_file.is_good()){
      out_file << "\nHello, World";
      out_file.close();
   }else{
        cout << "Error Opening File";
        cin.get();
   }

   return 0;
}

Chris

Freaky_Chris 299 Master Poster

without the function call aswell it is hard to see what the problem is.

Chris

Freaky_Chris 299 Master Poster

I think you forgot to state what the problem was, all you did was post the problematic code and a whole lot more code...

Chris

Freaky_Chris 299 Master Poster

Is that even possible? How can a computer program know if sound is actually coming out of the speakers or not? But maybe there's some interface with the sound card API that will indicate that ???

My guess would be it would get even more specific...I.E different for each sound card, if it is possible. I guess you could always check to see what is being SENT to the sound card

Chris

Freaky_Chris 299 Master Poster

Just a though but you may need to be a little be more specific when you say graphics... also i would suggest pasting some sample code, that demonstrates the problem

Chris

Freaky_Chris 299 Master Poster

Can you not adpot what i gave you....or am i gonna have to spoon feed you?

ostringstream hello;
    char buffer[10];
    buffer[0] = 0x05;
    string blah;
    
    hello << hex << (int)buffer[0];
    
    blah = hello.str();
    TextBox->Text = blah;
Freaky_Chris 299 Master Poster

You could always use something like this....ofcourse you need to adapt it

#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main(void){
    
    ostringstream hello;
    
    hello << hex << (int)'A';
    cout << hello.str();
    
    cin.get();
    return 0;
}

Chris

Freaky_Chris 299 Master Poster

Whats wrong with cstdlib & cstdio, this is C++ not C.

The previous post uses string stream which are brilliant for this. You may also want to consider looking at strtol().

Chris

Freaky_Chris 299 Master Poster

Battleships, thats quite a nice game to make.

Chris

Freaky_Chris 299 Master Poster

The problem is that always when I try new codes from msdn.microsoft.com, my compiler CodeBlocks always returns errors while compiling. I tried those codes but Codeblocks says: "Error: 'main' must return 'int'."

When you use sample code from msdn, you will have to change

void main() //change this

//to this
int main()

it should always be int main.

Chris

Freaky_Chris 299 Master Poster

Google -- http://msdn.microsoft.com/en-us/library/aa364418(VS.85).aspx

Always read up on functions before you try and use them.

well i think you forgot to declare the variables pathSz, pathBf & bufSz or at least in that scope.

Chris

Freaky_Chris 299 Master Poster

Hmm....

code tags, there a nice thing
[code=c] [/code]

Also this looks like C to me not C++
Could just be me but i'm quite sure its not C++

Chris

Freaky_Chris 299 Master Poster

Why socket programming for indexing of files on a network drive?..
Better search inet on this topic. I think it's a project for some years of hard work...
Good luck!

actually very good point! lol i was having a reallllly blonde moment.

Freaky_Chris 299 Master Poster

Just to note, this sort of thing is better done with a macro

#define SIZE 101

Chris

Freaky_Chris 299 Master Poster

Yes it is.

Freaky_Chris 299 Master Poster

think you may need to use the & operator before the variable you are passing.

Chris

Freaky_Chris 299 Master Poster

Firstly look at socket programming, to start understanding how to work over a network

Chris

Freaky_Chris 299 Master Poster

Read the file line by line, split it into tokens based on spaces, then convert the number token into a double from a string.

You may want to look at.

getline()
strtok()
strtod()

Hope that helps,
Chris

Niner710 commented: Thanks for the response. +1
Freaky_Chris 299 Master Poster

Now, to make it more portable, and to eliminate the "magic numbers" do the arithmetic using the actual characters.

Clever little problem. I like it. I may torture my own students with this sometime. :twisted:

That was how i inteded to do it, doing the arithmetic with the actual characters, i just went along the line of explaining numbers so he knew where i was coming from :P

Yer it would make a nice little problem for quite a few classes i imagine, i can't wait till i start computer science and get to have a ready source of problems :twisted:

Chris

Freaky_Chris 299 Master Poster

Yet another tip: you can get "mirrored" char with only one and a very simple expression without any explicit numbers...

Now thats a new one to me, normally i can thing of these thing straight off the top of my head. But not this one lol otherwise i would of suggested it. I spend quite a bit of time finding quickest ways to do things but this one got me :P

Freaky_Chris 299 Master Poster

i would suggest looking at the ascii code for the character. To start with the ascii code for 'A' is 65 and for 'Z' is 90, there rest lie inbetween unsuprisingly. You first step would be to determine ig it is on the right or left hand side. So is it <= 77 or >=78 once you have this then you can carry on.

Once you have done that then you can go about subracting, and adding values to and from the numbers 65 and 90. I'm not going to go into too much detail ill leave you with something to think about.

If you get stuck with it then we can provide more help. But that should be more than enough help for now

Chris

Freaky_Chris 299 Master Poster

she wants it to do whats in the description

You haven't actually presented us with a problem. You have said it should do this, and not actually pointed out where you are stuck...we don't do it for you we aid you. We are not going to write entire sections of code for you.

Have an attempt to make it do what you asked, if you get stuck then post and tell us what the problem is.

Thanks,
Chris

Freaky_Chris 299 Master Poster

I think i have missed the actualy problem here. Could you explain why you are having trouble with integer division.

I see no reason for it not to work if you use doubles.

Chris

Freaky_Chris 299 Master Poster

So besides ignoring the fact i told you to use code tags, you have posted ALL of your code anyway.

Also narrow it down a little bit, rather than just postig the whole lot with an error message

Freaky_Chris 299 Master Poster

Firstly you will need to use API's calls. Secondly you will probably need to know something about what information the Joystick actually sends to the computer and how it is interpreted by the driver application for it. Once you know that then you can start work on writing a wrapper.

Chris

Freaky_Chris 299 Master Poster

Very little information here, also i've never programmed microcontrollers in C++ only a version of assembly. However the name bsend indicates bitsend And so that would mean its sending bit via the output pin.

Chris

Freaky_Chris 299 Master Poster
int myArray[10];
myArray[0]= 1;

That is the array index, note arrays are 0 index'ed meaning the first entry is always at 0 never 1

Chris

Freaky_Chris 299 Master Poster

1) Code Tags
2) Provide all the code that is the problem - this is may include header files etc

Chris

Freaky_Chris 299 Master Poster

1) How doesn't it work? - What errors do you get?
2) Does it compile but not give the expected result?
3) Which section of code is or do you think is the problem?
4) use [code][/CODE] tags

If your using C++ code why are you including things such as stdlib.h instead of cstdlib etc?

Chris

Freaky_Chris 299 Master Poster

No there isn't and again no.
You would have to write your own. Search the forums its a VERY popular question.

It will turn up alot of material for you to look at, including recursive and non-recursive.

Chris

Freaky_Chris 299 Master Poster

> EDIT: im using windows xp pro, if that helps.
But which compiler?
Not some fossil like TurboC by any chance?

> send a high or low signal to the corresponding output pin on a serial port
Er, you do know what a serial port looks like right?
Or even how a serial port works?
http://www.lammertbies.nl/comm/cable/RS-232.html
The only output pins which have a level associated with them are CTS and RTS.

Why are you providing this information. I can't imagine someone trying to work with serial ports if they don't know the first thing about them.

Thats about as bad as if i was to set out writing a driver program in assembly for a microcontroller to interact with a keyboard. And then not looking at how the keyboard transmitts and recievers data.

That was a fun project btw, i also did it using shift registers aswell as assembly. I'm a bit of an electornics geek too :P

Chris

Freaky_Chris 299 Master Poster

Just to summerise incase you don't bother reading, which wouldn't supprise me.

1) We do NOT do homework
2) We WILL help if YOU provide proof of attempts
3) Show where you are stuck
4) Provide detailed information about your problem

Chris

Salem commented: Helping to get the message across +23
Freaky_Chris 299 Master Poster
/*BINARY SEARCH PROGRAM BY SUMAIR IRSHAD*/
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
int arr[]={1,3,5,7,9,11,13,15,17,19};
int i,target,start=0,end=10,mid;
printf("enter target");
scanf("%d",&target);
while(target!=arr[mid])
{
mid=(start+end)/2;
if(target==arr[mid])
{
break;
}
else if(target<arr[mid])
{
end=mid-1;
}

else if(target>arr[mid])
{
start=mid+1;
}
}
printf("target found at %dth location",mid+1);
getch();
}

Where to start.

1) Use code-tags
2) use int main() not void main()!
3) This is a c++ forum not c

Chris

Freaky_Chris 299 Master Poster

First of all do u know what a bucket sort is? :D

I'll agree with this, you should do some research as to what a bucket search is.

Also how will you be implementing it? Will it be a recoursive bucket sort and thats it. Or will it be a bucket sort followed by another sorting algorithm such as a quick sort.

I'm guessing it will be a solo bucket sort, wikipedia has some good information on how to implement a bucket sort.

Chris

Freaky_Chris 299 Master Poster

It works. I just figured it out this past Sunday.. I am new to the programming world so my "style may not be too good..

Your using C syntax in a C++ forum....

Also use [code][/code] please

@OP
rounding it off can be done by adding 0.0005 etc which which ever number of zero's it requires

Chris

Freaky_Chris 299 Master Poster

Still learning you still seem to have the problem of the fact the first character is not printed. This is because in your loop to print it out backwards you are checking to see if it is > than 0 baring in mind that arrays are 0 index'ed that means that it should be => 0.

from OP you said you were getting smiley faces well thats because you are accessing uninitialized areas of memory.

Also as far as header files stand. I would advise you do not take your teachers advise in the fact you should use them because he doesn't like them.

I would use them anyway, its good practice too.

Chris

Freaky_Chris 299 Master Poster

menu (char symbol); Should be menu (symbol); Chris

Freaky_Chris 299 Master Poster

Why are you defining your own PI when cmath comes with M_PI which is alot more accurate than yours?

Chris

Freaky_Chris 299 Master Poster

For reasing the data i would use a while loops thats condition is the file reading operations its self such as

while(getline(afile, myString)){
//code here
}

Chris

Freaky_Chris 299 Master Poster

count your opening and closing brackets

Freaky_Chris 299 Master Poster

using console redirection is not how to read from a text file, http://www.cplusplus.com/doc/tutorial/files.html

is an example of how to read from a text file although it incourages bad things such as while ( !eof ) and .is_open().

But thats for another day

Chris

Freaky_Chris 299 Master Poster

hmm not to sure why that would be it seems ok to me....

one thing i wanna point out is as follow's its just a little neater

case 'R':
                rev_str();
	break;
case 'r':
	rev_str();
	break;

is the same as

case 'R':
case 'r':
	rev_str();
	break;

Chris

Freaky_Chris 299 Master Poster

just a note on the loop

while (STAMINA || ENM_STAMINA != 0 )

I'm not to sure what you think this means exactly (althought its ok this time), but im guessing its not what it actually means. it would be evaluated as follows

while ((STAMINA) || (ENM_STAMINA != 0) )

not

while ((STAMINA || ENM_STAMINA) != 0 )

Hope that makes sense

Chris

Freaky_Chris 299 Master Poster

Is it just me that thinks this or are cmath & math.h the same thing?

Chris

Freaky_Chris 299 Master Poster

Would it not just mean adding some form of a break in the text file?

For example enter an 'x' after the first matrix, then the program knowns it finished and can call again for the next.

Maybe i missed something?

Freaky_Chris 299 Master Poster

Shouldn't thisbe the other way around? parse=newzipcode; so this... newzipcode=parse; Maybe i missed something

Chris

Freaky_Chris 299 Master Poster

windows.h has a Sleep() function, this will allow you to stall the application for a short period of time each loop, thus reducing the processor usage to 0 or almost.

Chris

Freaky_Chris 299 Master Poster

the code is the declaration. You call it use
t.merliv(5)

And which other code compiled?

Chris