Sci@phy 97 Posting Whiz in Training

do loop. And inside while add check ch != 'q'.

And you have to cleverly put menu printout somewhere inside :)

Sci@phy 97 Posting Whiz in Training

You don't need two loops (do, and while). Try to implement just one. (think, think :) )

Sci@phy 97 Posting Whiz in Training

Line 30: return 0; should be inside main function

Sci@phy 97 Posting Whiz in Training

float monitorhire ( float hireleft,float hireout) ; This is wrong declaration inside main()!

Advice: don't use so much global variables (none would be best)

Sci@phy 97 Posting Whiz in Training

Have a look:
set

Sci@phy 97 Posting Whiz in Training

You're getting char with cin.get(ch) inside while function. You don't need cin>>ch; before (it steals one char from you)

Sci@phy 97 Posting Whiz in Training

Guessing game? Well, ok... what kind of guessing game?
And if you really have code, post it, please.
And use code tags!

Sci@phy 97 Posting Whiz in Training

You have declared y inside for loop, so that means it only exists in for loop. Declare it before for!

Sci@phy 97 Posting Whiz in Training

Umm, your code?

Sci@phy 97 Posting Whiz in Training

For hundreth time: you don't call void function like: void myfunc() but by simply typing: myfunc() And what do you want with divide_by_zero()?

Sci@phy 97 Posting Whiz in Training

Although, if you're doing it for class of some sort, wouldn't it be better to make your own toupper? Just a thought.
Remember, letters are stored actually as ascii code, and you can "add" them or even compare them ('a' > 'A' i think, maybe opposite)

Sci@phy 97 Posting Whiz in Training

can't figure out what I'm doing wrong....

A lot of things!
First, recheck your syntax, there are many errors.
And you cannot declare void function and then expect to get some result from it!

Sci@phy 97 Posting Whiz in Training

double y[41]?

I'm not checking a logic of your program since I don't really know what it's about, but first set your syntax straight, then fix logical errors

Sci@phy 97 Posting Whiz in Training

You don't even need that, since you have a number before your matrix that tells you how big it is.
Simply add second number after that, do some sort of while/for/do-while/goto loop (ok, maybe only while or for :) ) and it should work.
If you want more help, post your attempt (that is, attempt to read more matrices, not just one)

Sci@phy 97 Posting Whiz in Training

Err#1: this semicolon here: double getTheoreticalData(double x); This is not necesarry: double PI; Since you have included "cmath" header, you already have M_PI defined, and it's more precise than your PI!

Err#2,3: y[] is not declared, z[] is not declared
Err#4: after return 0; you need closing bracket '}' for main()

Sci@phy 97 Posting Whiz in Training

Easy :)

But now, do you want us to code it for you?
Or would you like to try it yourself?

Sci@phy 97 Posting Whiz in Training

Your code doesn't even compile properly.
What is this: if(nho>0) fix it

Sci@phy 97 Posting Whiz in Training

while( chioce != 'n' );} should actually be: } while( chioce != 'n' ); Have a nice coding :)

Sci@phy 97 Posting Whiz in Training

I am unaware of any compilers that are C only designed in the last 18-20 years, especially based on the recommendation to get a new compiler. Virtually all compilers today are C++ compilers and, since C++ is (guestimate) 75% or more C, they all compile C without problems.

Will turbo C++ allow C99 standard things? If it compiles C code, not C++.
(I don't know if a turbo c++ compiler can compile C like plain C or it compiles it as C++?)

Sci@phy 97 Posting Whiz in Training

Nonetheless, it would not be very clever not to check the return of it.

Ahh, I knew someone will say something like that :)
Of course it can be dangerous, so are pointers (but we still use those).

Also, FYI, see this and this about scanf() . Why instructors insist on teaching bad techniques I still have no idea. Maybe someone will ask sometime and post the response.

For first this I have only one answer: scanf("%40s", string); For second this: yeah, you got me there, but I'm not talking how scanf is very cool, just that it CAN do a lot of things.

Sci@phy 97 Posting Whiz in Training

I think that for binary search you need sorted list... so if you have unsorted array, linear search will have to do.
Otherwise, binary is faster

Sci@phy 97 Posting Whiz in Training

And yet, scanf can be clever function:

#include <stdio.h>

int main(){
    char dump, string[40];

    printf("Enter whole sentece (yeah, bring spaces too, I can handle it):\n");
    scanf ("%[^\n]", string);
    scanf("%c", &dump);
    printf ("You entered: %s", string);
    return 0;
}
Sci@phy 97 Posting Whiz in Training

I tried to count lines to see which one is line 39, and I managed it

case 'I' : case 'i ' :

Notice that second 'i ', do you see a difference between:

'i'
'i '

First is valid, second is invalid!
Change that first

William Hemsworth commented: Well spotted :) +4
Sci@phy 97 Posting Whiz in Training

Reason is that sstr is set to false AFTER trying to read after EOF. So first you read last item, it's ok, when while sees no error, continues, but you can't read more, so x is assigned to last good reading (last number) AND then sstr is set to FALSE!

You need this: while (sstr>>x){//do stuff with x}

Alex Edwards commented: And I thought it was because the input and output flags weren't on - good deduction! +4
Sci@phy 97 Posting Whiz in Training

your problem is cin>>char_var;
Why? When you enter something on your keyboard and then press enter you have entered more characters. eg:
YOU ENTER: p
CHARS IN BUFFER: p, '\n'
That '\n' is from the enter you pressed, and you have to get rid of it before next input.

So, after every cin insert: cin.ignore(); That will work if you only enter one digit (p, or s...)
If you want it to work even if you write a novell ( :) ) write: cin.ignore(numeric_limits<streamsize>::max(), '\n'); HTH

Sci@phy 97 Posting Whiz in Training

Remember that array is double pointer, just like ar. You cannot write ar[x], it is 2D array: ar[x][y]!

Sci@phy 97 Posting Whiz in Training

  1. First you write code in some text editor. It doesn't matter what editor, it could even be notepad.
    Then you have to compile that code.
    Compilation refers to the processing of source code files (.c, .cc, or .cpp) and the creation of an 'object' file. This step doesn't create anything the user can actually run. Instead, the compiler merely produces the machine language instructions that correspond to the source code file that was compiled. read for more
    Compilation error is therefore something that occured during this phase, most likely syntax error (misspelled some function name, or trying to do something that C doesn't allow)

    So, after compilation, you have object files. In simple programs you have only one object file, so it's difficult to understand need for it (why not just build everything at once?).
    But if you have more different files that you want to merge into one program, first you have to compile every single one into object.
    Then it's linker's job to take all object files and to make executable out of it.
    Linker error is most likely definition/declaration error (you can have function defined in one file, and declared in another. If these two aren't identical linker error occurs).

    Runtime error 99% of the time has to do with evil horrible pointers. It happens at the time program is working, and therefore, the mistake cannot be located so easily.
    Mostly has to do with program …

Salem commented: Nicely put +22
Aia commented: Nice effort. +10
devnar commented: Very well explained. Thanks +1
Sci@phy 97 Posting Whiz in Training

From my head :P

Seriously, reallocating for every integer may not be SO time consuming because on most of the time, realloc could just append to existing memory space. But it still IS time consumin considering the time that takes for that function to do it's stuff :)
So, define some number at begining of your code (I said 100 because I wouldn't go below 50, it's not a big size for 1GB RAM, and wouldn't go above 1000, it seems to me a pretty large number, although 1GB is 1GB :) ) and see is your program running smoothly... Then maybe try increasing/decreasing...

Basically, you need std::vector from C++.
Try to find something about it on net, and then try to make something like that in your C code. Here's one link:
http://www.cplusplus.com/reference/stl/vector/

And this is how std::vector reallocates:
whenever it runs out of space, it doubles the size of itself. Maybe you could try something like that?

Sci@phy 97 Posting Whiz in Training

Well, if you're not going to acces members randomly but from begining to the end, maybe list would be perfect?

On the other hand, you could use realloc for every n members (you choose n, but I wouldn't go over 100 if user input is small)

Sci@phy 97 Posting Whiz in Training

I'm sorry, but your code is quite big. Try posting one question at a time, event if it means opening several threads at once.

Sci@phy 97 Posting Whiz in Training

It should be like this (yeah, I like writing nonesence):

int i = 0;
while ((string[i++] = getchar())!='\n');
string[i]='\0';
Sci@phy 97 Posting Whiz in Training

I believe (but since I'm not familiar with IP thingies, I'm not sure) that you are assigning a bool here: in_addr_t ipaddr = inet_addr( s ) == -1 Is the same as in_addr_t ipaddr = (inet_addr( s ) == -1) So you should write: (in_addr_t ipaddr = inet_addr( s )) == -1 but it gives you compile error, so simply try to make in_addr_t outside if statement.

And also, I believe if you declare something inside if (here) it exists in else?

Sci@phy 97 Posting Whiz in Training

I'm using Visual C++ and doesnt give me any compilation error it keeps giving me a run time error after i enter the 1st number i can't figure out whats wrong :S help?[/QUOTE]

The only reason this code should give you error is if you input something else that float, let's say letter. So please post what number did you entered for its first input?

And please, write:

int main()

instead of simply

main()
Sci@phy 97 Posting Whiz in Training

Please mark this thread solved then

Sci@phy 97 Posting Whiz in Training

well, show us your timeGetDevCaps function for start :)

Sci@phy 97 Posting Whiz in Training

int has it's largest number, and you can't insert a larger number in it than that.
But I don't think that's even point. Your code asks you to input each digit in NEW LINE. Inputing them on same line will produce digit larger that nine, and thus output: "Invalid Input. Please try again.!!"

Sci@phy 97 Posting Whiz in Training

//i am not sure how to implement an array of linked list without vector

And that's why I always say: start with C first.
If you're making linked list, you don't use [].

Inside your main() you just hold head pointer which points at first node.

Your create_node code has to be something like:

int create_node(node* head, int a_size, int a_stat){
    //now we create new node using malloc function, similar to new in c++
    node *temp = malloc(sizeof(node));
    
    //on error (node is not created)
    if (temp == NULL) return -1;

    //temp is now pointing to that newly created node, let's fill it
    temp->size = a_size;
    temp->stat = a_stat;
    temp->next = NULL; //new node points at nothing
    //and now tricky part, as we want our new node to point to previous node
    node* prev = head; //prev is pointing to first now
    if (prev == NULL) //this is actually first node
        head = temp; //so head should point to it
    else{ //but if it's not
        while (prev->next != NULL) //loops until last node in list
            prev = prev->next //advance to next node
        //while has stoped, now we link our newly created node to back of list
        prev->next = temp;
    }
    return 0;
}

I think I've been more than helpful :)

Oh yes, and, code is not compiled, so there possibly are some errors

Sci@phy 97 Posting Whiz in Training

I (and presumably lots of people) don't understand your question at all.
Maybe providing us with some example of what you want to do or something

Sci@phy 97 Posting Whiz in Training

H!

//everything good till this:
For that you just use fflush(stdin) after each input line. so that it will clear(flushes) the previous 'new line' character and take the input correctly.
Try out it!!

In C standard fflush accepts only output buffers, not input.
Although most compilers do clear std buffer if you write fflush(stdin) it's not a good idea to do that, because generaly, there is no rule to fflush(stdin). So you never know what will compiler do with it.
The best would be to write your own flush function, and code for it is provided by ahamed101 in previous post, as many times before :)

Sci@phy 97 Posting Whiz in Training

The only problem is he can't use name "continue", it's c++ keyword ;)

Sci@phy 97 Posting Whiz in Training

Use strcpy(string_to_be_copied, string_with_values_to_be_copied) to copy one string to another.

Sci@phy 97 Posting Whiz in Training

Using stack without dynamic mem allocation is like... ummm... using stack without dynamic mem allocation (LOL)

Sci@phy 97 Posting Whiz in Training

I still think it's best practice for new beginners to use simple compiler like g++. In that way they are going to learn difference between compiler and linker, and will have to write their own make. They can only benefit from that :)

Sci@phy 97 Posting Whiz in Training

Well I presume you could make one operator, that returns pair!

pair<int, char>& operator(int index) const

pair is built in container that has members first and second. So, this is how it would work:

Base my_base;
//...some code between
pair<int, char> store_info;
store_info = my_base[3];
cout<<"This is int on position 3: "<<store_info.first<<endl
     <<"This is char on position 3: "<<store_info.second<<endl;

And one more thing about declaring operators.
Basically, your [] operator won't change object members, so it's best to make it const (that last const).
const keyword is not needed in argument, since it's argument you are passing by value, which means it can never get changed.

Sci@phy 97 Posting Whiz in Training

Just to mention, you don't have to declare char ptr, you can simply cast string: (LPVOID)"HELLO"; But, if you want your string to work inside function that you call, you have to typecast it back to (char*)

Sci@phy 97 Posting Whiz in Training

*cough*
Dev-Cpp

THIS compiled ok on dev-cpp:

int main()
{
    DWORD   dwThreadId;
    HANDLE  myThread; 
    void *ptr=NULL;
    
    myThread = CreateThread( 
            NULL,                   
            0,                       
            MyThreadFunction,      
            ptr,           
            0,                      
            &dwThreadId);  

    while(1){
             Sleep(3);
             std::cout << "main";
             } 
    std::cin.get();
    return 0;
}

notice the void* ptr; I suspect problem is in your "HELLO", not in dwThreadId

[edit]And Narue's code compiles on Dev :)[/edit]

Sci@phy 97 Posting Whiz in Training

Use code tags, and ask more specific question

Sci@phy 97 Posting Whiz in Training

Of course you cannot overload operator[] in that way!
Since it has same type of argument, program won't know to which one are you reffering (sice it doesn't check type that you use to hold return value)

Answer: You CAN'T do that

Sci@phy 97 Posting Whiz in Training

I would recommend g++ (linux, or win) because it's real compiler, and not IDE.
Since you are beginner, it's better to start with plain old compiler :)

Sci@phy 97 Posting Whiz in Training

You could write your hex-to-deci function, and then you can simply write char a = hex-to-deci-function(hex_num)