WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

So, correct it...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Is this a joke?

Not only do you
1) resurrect and hijack an old thread
2) not use CODE Tags
3) post over 2000 lines of bad code
4) use a compiler and functions that haven't been used in 20 years

you also expect us to read it, understand what you're doing, and find out not only what the problem is but where. Heck, you can't even be bothered to tell us what the error is!

There might be someone willing to take this on, but most of us won't touch it.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Your problem is the variable you defined to hold the string is just a pointer. There is no space to actually store the value.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

So what's the value of w->name after you read it?

When asking a question, give us ALL the details necessary to understand the problem. For example, how do you know that statement is the problem?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Look up the functions RIGHT() LEFT() MID() and LEN().

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Try thinking about the answer. Where do YOU think the output makes sense?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Since you seem to be getting answers that don't come close to a solution, maybe you need to describe again more clearly and in detail what you are trying to accomplish.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

When is department == "" ? Are you sure?

If tests don't work, you need to verify the variable values. Output them, or use the debugger.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

it is already included mate

Look again, mate...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Or better yet puts(str1);

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Dev C is a C++ compiler. But, like most compilers, it can compile strict C programs as well.

And yes, given the right knowledge, you will be able to write the program you want.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Stop trying to fix his code! It's correct.

The problem is your terminology. You said

From that point, I go to the command line and after making sure I'm in the correct directory, i type "gcc dumb.c -o dumb" (no quotations obviously) and that's how i run the program.

That command only runs the compiler, not the program. You don't have a program yet.

Once compiled (and linked for those here who are anal about it) you still have to run the program. See the last part of anirudh33's post.


Also,

I know the program is working (sorta) because it doesn't give me any error message.

That's no guarantee it's working. It only means it compiled. Your syntax is all correct. But the program can still be wrong.

#include <stdio.h>
int main()
{
    int v;
    v = 2+3*5;
    printf("2+3 multiplied by 5 = %d\n", v);
    return 0;
}

This code works using your definition (no compile errors) but it's still wrong.
Why? :icon_wink:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Yes, firstPerson is correct. srand() should be called only once, at the beginning of main() .

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

A quick inspection of the code reveals that your not resetting the variable judgeCounter back to zero.

A note on code indentation...Please use it.

Yes, but don't use gerard's formatting. Indent 4 spaces, not a full TAB. TABs make the code hard to read.

Your IDE can be set to convert the TAB to 4 spaces so the code looks good no matter where you post it.

IOW, TABs are evil. SPACEs are wonderful. :icon_wink:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I noticed you guys on this forum don't use

using namespace std;

but I thought it was more a matter of style other than anything else...

You will notice if you actually look at this forum that we DO use using namespace std; . Many of us don't necessarily subscribe to the idea Moschops set forth here. Note he only has a few posts here and therefore speaks for himself, not the forum as a whole.

This is not to say his idea is incorrect. Only that it is not a forum wide policy.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Congratulations.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You can use cin.get() to read each individual characters from the stream.

... read it in as a string and access the digits as characters...

How do these suggestions support

If a user inputs a int number, say 150...

:icon_question: :icon_rolleyes:

As jonsca alluded to, look up the modulus (%) operator. Used in conjunction with division you will have your answer.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Alphabet input can be checked by conforming that whether the input given is a character or not by comparing the input with the ASCII Codes of the alphabets if the inputs's ACSII code is in between the Charter's ASCII CODES series then the input provided is the character

Man, those translation sites really do a great job, don't they?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Hi everybody
I wrote this code in my university assignment . But I want to change the global variable (the variables that above the main) to local variable (inside the main) and add the parameters in the functions.

Ummm, OK. So do it...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

What you did is perfectly acceptable.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
while (select < 'A' || select > 'E')

Single quotes denote the character

i dont want the program to accept alphabets only numbers

You could look at my suggestion and maybe convert it into something you can use.

That's the idea behind programming. Take something similar and make it fit your situation.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Output d as a hex value, or use a decimal-hex calculator to check the answer.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

toupper() is working fine. You just didn't store the result anywhere, throwing away the modified character.

As for line.size , what was input, what is the result, what were you expecting? Remember to give the details necessary for full understanding. Otherwise you get guesses and inadequate help.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Yes

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
while (select < 'A' || select > 'E')

Single quotes denote the character

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

When you start the int with a zero, I think it's getting interpreted as an octal number and then output as a decimal conversion of this.

But not if the value is input. Only if defined in the program.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

feel free to edit or modify the code, its been a long time since I have played around with this code :)

Then you should have played with it before posting. goto and gets() are extremely poor techniques in coding. And for a professional? At M$? No wonder updates are needed continuously...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

NULL is 0. There is no distinction between a variable with no value vs. 0. As jonsca said define a value as your "no value" number.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

How about giving an example of exactly what you want. Telling us it works 121314 doesn't tell us what is correct. Examples help.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Just out of curiosity,
Why did you say this? @Waltp

Because we are asked to guess at what the problem could be since no details were forthcoming. So I guessed.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Use CODE Tags!!!

Do you have a question or do you just want us to test it for you?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

strings are collection of characters that you enclose it with double quotes.
eg:

char a[5]="world";

a[0] will have w
a[1] will have o
a[2] will have r
a[3] will have l
a[4] will have d.

Would you care to correct your description and not blow past your array boundaries?
And add the required information on \0?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Just read up on how to open,read,write,close a file, as I posted. mitrmkar's suggestion is too high level for a beginner, and if you do it wrong, you could kill your computer.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Another example:
You want to know what lights are on in your computerized home.
Bits:
0- Front Porch
1- Entryway
2- Living Room
3- Dining Room
4- Kitchen
5- Bathroom
6- Master Bedroom
7- Kids Bedroom

In the lights byte you have

Byte value  00110101 
Bit numbers 76543210

Which lights are on?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Next time EDIT or DELETE the other post. Don't just leave it for us to clean up.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Why would a new programmer that barely knows the language be concerned with race conditions? Let them learn to program before you get into high level concepts.

And CreateFile is not a standard C function. Therefore it's not portable and should not be taught at the beginning level programming.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

An INI file is just a file that you define. It's a text file containing the data you want to write to it. It's not a special file, it just has a different extension -- .INI

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
puts("please enter a file name to create:\n");
scanf("%s", &file_name);    // Never use scanf() to read a string.  It's dangerous. Use fgets()

if( create_pointer = fopen(file_name. "r"); 
printf("file already exist"); 
else
{
if(create_pointer != fopen(file_name"r");   // Didn't the previous fopen already check for this?
create_pointer = fopen( file_name, "ab");
}

You'd want to:

open file for read
If opened
    close it
    set flag to 'exist'
  else
    set flag to 'not exist'
endif
--continue--

But, based on your examples, if you are opening the file for append ("ab") why does it matter? The file will be created if it doesn't exist.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Don't call main() from your functions. return instead.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I will still help. But you must do the work. What part of my suggestion do you not understand?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I agree -- for experienced users that understand the O/S. I myself edit the registry often. But for new programmers, it's extremely dangerous. If it's so safe, why does every registry hack include a disclaimer... (objection sustained)

Yes, your code checks for errors. 99% of posts on these forums asking for help don't. I would not suggest registry programming except to experts that already utilize safe coding practices.

My 2 cents...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Change your IDE/Editor to convert TABs to SPACEs. That will solve the problem...

jimJohnson commented: Great helper +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I can't even follow your code with the formatting you have. Please re-format and post again.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You didn't type the filename in properly. And after 3 years, are you even sure prushik is even around?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Why not just make an icon for the program and put the in the STARTUP folder of the program list?

This way you won't destroy your registry file if you get the code wrong.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Start at the end of each array (ones digit).
Add the two values.
If < 10, store in the last entry of the answer array
If >=10, store (val MOD 10) instead
         save (val / 10) to add to the next digits
Move to the 10's digit and repeat
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Get a random value MOD 2. If 0, output to out1.txt. If 1, out2.txt.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You're moving the wrong value into AH