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

By not using scanf() to input your data. See this series to see why, and how to fix it.

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

P.S Refer to my reply to your mail.

As I'd said privately....

No one should be answering private requests for help. That's because no one should be asking for private help. Help is what these forums are for. Keep all questions and answers in the forums, please.

Not disputing what you say, Dave.

It's a matter of what the OP's problem is here, and how I (and at least one other) have been trying to help him around it.

And Dave is trying to clear up misinformation being passed to the OP. Though not directly related to his problem, telling him there's an EOF character is teaching him 'bad grammar' which he will pass on to the next person. So don't argue with Dave. He's trying to help, too.

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

Man you have to keep in mind i have been doing this for only two months. I am trying really hard to learn the ropes, so please refrain from giving me crap about writing code and formatting because i do what i think is "correct formatting". I am trying my very best and appreciate all of the help, because this stuff is very overwhelming to me and i am trying hard to understand it.

I'm not giving you crap. You don't have to get defensive. If you are trying to "learn the ropes", doesn't that include learning how to format your code correctly? Especially from a professional programmer? If you are new to programing, how can you expect to have "correct formatting" yet? I'm simply pointing out one way to learn it.

If you format your code properly
1) You will be able to follow it easier
2) We can follow it easier
3) We can give you better and faster responses because the code's easy to read.

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

Maybe if you'd format your code properly you wouldn't have this bracket problem. Give it a try, please.

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

How do you expect to use a database management system and not have to install it?

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

I have my code written very nice on my compiler with proper spacing and good alignment, how do i put it on daniweb so it looks like my compiler. everytime i make a thread and space it right the preview of the post looks messed up....

1) You could read The Rules as requested when you registered.
2) You could read the post titled "Read This Before Posting" at the top of the forum
3) You could read the words on the background of the box you typed all your messages in.
:icon_rolleyes:

Check out this link on how to do it (I'm linking rather than showing you myself because I myself haven't figured out how to make it display the words "code=C++" and "/code" as text without it getting interpreted as code).

You mean like enter code? :icon_wink:

VernonDozier commented: Cool BB Code +1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

A "database" does not have to be a pre-written data management system. It can be a file or three that contains the data you need for a project, and a few routines you write to access the data. Use the KISS principle (Keep It Simple Stupid).

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

Another thread with the same question. Closing.

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

Follow your code:

int main(){

	const int size=30;
	char filename[size];

	cout<<"Enter the file name that you will like to encrypt: \n";
	cin.getline(filename, 30);

	fstream dataFile;

	// open your file for OUTPUT
	dataFile.open(filename,ios::out|ios::binary);         
	if (!dataFile){
		cout<<"could not open.. exitting\n";
		exit (1);
	}

	// create a char buffer.  It just contains junk because you did 
	// not initialize the contents
	char list[size];                           

	// Overwrite your file with the junk
	dataFile.write(reinterpret_cast<char *>(&list),size);    

	if(dataFile.fail()){
		cout<<"failed to write..exitting";
		exit (1);
	}
	dataFile.close();

	char filename2[size];

	cout<<"Enter the file name that you will like to create: \n";
	cin.getline(filename2, 30);

	// encrypt the junk
	for (int i=0; i<size; i++){
		list[i]+= 10;	              
	}

	
	ofstream outFile(filename2);

	// output the junk
	outFile.write(reinterpret_cast<char *>(&list), size);  

	outFile.close();

	return 0;
}

If you comment your code, you would have seen the problem (I hope). The only thing is you must comment based on what the code itself tells you, not what you think it's doing.

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

So what's the problem, other than not using CODE tags as requested in the Rules. Maybe you need to read Read Me: Read This Before Posting too.

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

The string with the %x symbols in it are parsed to find each symbol. The letter is then looked at to figure out what field is supposed to go there. Then the string is changed by removing the %x and whatever field is requested replaces it.

Usually the data comes out of variables and/or structures the program has already read or generated.

There is no function to do this if that's what you're looking for. The function is written by the programmers developing the system.

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

>now how do i delete this thread?
We don't delete threads just because the original poster's question is answered. However, if you want, a moderator can mark this thread as "solved".

You don't need a moderator to mark a thread solved. If you are the original poster and got the answer you need, you mark the thread solved.

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

Jboy05, it's rude to post continuously just to bump your thread. The people here have lives outside the forum and 9 of the 14 posts here are yours. Patience!!!

Next, ignore everything zhelih said. Stacks are not needed at all.

Do you know how to use a while loop? Do you know the % operator? I assume you know division (/). These are all you need.

If you get the last digit of the original number, that is the first digit of the reversed number (use %). Store it in the reverse integer.
Remove that digit from the original number.
Then get the 'new' last digit. Multiply the reverse value by 10 and add the digit. From there, think through the rest of the instructions and see what you come up with. Your while loop should be less than 6 lines.

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

Read this and this, please. They will help you in the long run.

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

You need to be more careful and detailed when writing your posts, and you need to preview your posts before you submit them. I put "code=C++" in quotes because when I put them in brackets, the web page didn't recognize that I wanted to display the actual words. I see you just posted with the C++ code tags so that's good, but you need to indent so people can follow the logic. That's the whole point of the code tags. The code tags are pointless when the spacing is so strange.

In other words
Read the Rules -- as you were asked when you registered.
Read This because it's title says you should
and Read This to understand proper formatting.

Yes, there's some reading involved, but you want us to be able to help you -- right? The more we can understand, the better the help.

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

Use the mod (%) opreator followed by the divide (/) operator to check each digit.

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

Hey everyone.. I'm having a little problem with something I'm writing for a class.. I'm supposed to use while and a nested IF statement in the solution, but every time I run it I get the following back:

Run-Time Check Failure #3 - The variable 'A' is being used without being defined.

Well, where did you assign a value to the variable A so you can use if (Assignment = A) Also, check you book for the difference between = and ==

See this about your void main(). I hope your instructor didn't teach you that.

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

Since your post is unreadable, please read the Rules as requested when you signed up, the post titled Read Me: Read This Before Posting (the title says it all), and don't ignore the words on the background of the box you entered your post into.

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

Reread chandra.rajat's post and do what he said.

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

but how can the c++ detectthat the data is student id and examcode?

Please take care in your posts. detectthat? foleslike?

C++ cannot determine what type of data it sees. You have to determine what the data differences are and program the code to understand the difference.

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

Also stop double-spacing your code.

And you do not need getch(). Learn to program without it.

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

A simple Google search came up with this in seconds. You might want to try it yourself next time. It's faster.

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

i have used shifting the characters to left if a matched character in s1 and s2 (two strings) is found...

If you're using C++ strings, why? Just use .erase() If you're using C-strings, that's the only way to do it.

can i post my code

How else can we look at it? Your problem seems to be the same as the OP's so I guess it's not a case of thread hijacking.

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

here's the code that i've done but it doesn't work correctly..can someone help me out?

First off, please be a little clearer. Explain, don't just say it doesn't work. Why doesn't it work? What does it do?

What I'd do is immediately after the FOR, start the WHILE (or preferably DO/WHILE). Use the WHILE to find each letter and remove it, look up STRING.ERASE(). Exit the WHILE when the current letter is not found.

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

although they look identical in notepad , i believe like you said, a space or tab character is added somewhere on each line by the system() function.
i tried removing spaces from the line created by the system() function and then using strcmp() but it still didn't work :/

Then that obviously wasn't the problem. What I'd do now is display every character entered in hex just before comparing and, as AD suggests, see if there are differences you can't see.

You also might want to post part of the file.

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

I am a new learner of C and I tried to write a program about searching a keywrod from a .txt file and counting the number of time that the keyword repeats

My program is below...it can't work...and I can't understand why....
can someone please help me...T_T
Thank you

Why can't it work? What does it do? Are you sure you are reading the file properly? Try displaying the words are you read them to see if they are correct.

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

Neither do we since you didn't tell us what they are.

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

Your problem seems to be trying to get your input commands to do the processing for you. That's difficult at best. Just read in the entire line as suggested and look at the line character by character. That is basically all cin.get() does anyway.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
do { 
		  if(getch()){
			switch (getch()){
			  case UP:
					hook_up();
					break;

but it dosn't do thins the way i would like them to be done.
Again I translated some variable or function names.

What happens now is that I need to press a movement key twice to get it happen.
Also the 'game' freeses for 5 seconds at the start of it.

Yep. getch() gets a character from the keyboard. The first one in the IF statement waits for a key, when pressed it returns the character pressed, which is interpreted as TRUE. Then you enter the SWITCH and have to press another key.

What you are looking for is kbhit() . This function returns TRUE if a key is ready to be read and FALSE if not key has been pressed. That's the function you want in the IF statement.

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

in that case can anyone point me to where there is a very detailed tutorial on how to use ifstream ?

I guess I was too subtle. Post your code as the link describes. Very often if we see the code we can figure out what to tell you. So far we're only guessing.

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

Maybe this will help. Note the title...

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

It would make more sense to use HEX values rather than DECIMAL. 223 is relatively meaningless, but 0xDF makes sense since each character is immediately translatable into binary:
D = 1101
F = 1111

223 would be considered a 'magic number' and should be avoided.

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

You didn't look hard enough. Didn't you run across the getline() method?

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

long int??? for what??? sorry i didnt get ur point..
i m using double to store the number of total permutation and an integer array[n] to store different permutations of n numbers...

Doubles are inexact. You can't have 2354.34 permutations. Therefore double is a bad choice.

And how will long int affect the running time of my program...

Floating point takes longer to compute. Granted in this program it may not make a noticeable difference...

also changing the memory model to large or huge...
i m using Dev-C++..where does this model means??? how to change it??

It doesn't. Jishnu obviously thinks you're using a very old compiler.

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

@scru
other than maybe spelling mistakes i dont see what i did wrong. computers remove from humans the need to consult dictionaries. unfortuanately that is not true on daniweb. anyway. that is redundend at this point. i was just pointing out that one could not readily understand what he meant. jasimp misunderstood him too. and many of you would have had i not figured out what he meant.

You seem to have a "don't give a damn" attitude.
1) Use a browser that highlights spelling errors. Mine (FireFox) flagged 3 above.
2) Sentences start with capital letters (A-Z) in English.
3) Contractions have apostrophes (won't, can't, you're)
:icon_wink:

>>spamming a forum
i dont see how advertising links in your signature counts as spam. i mean it does not harm anyone. and dani can claim a percentage of the profits and so it is a boon for her as well.

How can she claim a percentage?

I respect Daniweb's image of a not-for-profit community which consists of people giving their time freely because they enjoy it, rather than posting just to earn money.

"not-for-profit?" Somehow I don't think so. Dani has made it quite clear that this is not a non-profit site. The more traffic, the more she makes.

and even when he attempts to explain his insult he fails to make anyone see how it's insulting :)

I got it, without explanation :icon_twisted:

iamthwee commented: point's 1, 2 and 3 were priceless +13
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Also, please read this. Your titles are worthless as they are. This thread should be titled something like "Using user32.dll with Dev-C++"

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

the only problem with this is that it hasn't been taught to us yet (the *number[] part)..
so we have to use only whatever has been taught to us
i tried using nested if's but all those {} are making me dizzy, i keep getting errors and i cant keep track of my variables..

Then you're probably not formatting them correctly... :icon_wink:

just got back from school..

So? :icon_razz:

i got the 10-19 part ok now.. before when i type 312 it says three hundred two but its fixed now..
the only problem left is that it wont display ones digits..
i've gone over reviewing this many times but i cant figure out whats wrong..

Again, look carefully at this piece of code -- before Nick Evan gets here and tells you what I mean :icon_twisted:

if (z < 10 || z >= 20)
   {x = z % 10;}
else if (x == 1)
   printf(" one");
else if (x == 2)
   printf(" two");
...

How does this code allow you to get to printf(" one") ?

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

You might also consider using arrays for your 'words'. It would make your code shorter. For example:

char *number[]= { "", "one", "two", "three", "four"... "nine"};
...
x = z % 10;
printf( " %s", number[x]);

You can do this for all your numbers, including the teens and 10-90.
The 'zero' is blank because you never really output 0 in word form.

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

Look carefully at this section of your code:

if (x<10&&x>20)

x=z%10;
if (x==1)
   printf(" one");
...

You also might want to consider using more spaces in each line to make the code more readable. Something like:

z = num % 100;
if (z >= 20  &&  z < 30)
...
else if (z >= 40  &&  z < 50)
   printf( " forty");
else if (z >= 50  &&  z < 60)
   printf( " fifty");
else if (z >= 60  &&  z < 70)
   printf( " sixty");
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

My understanding re cin.clear() is that if the cin fails (eof or mismatch of data) then further access or use of cin is prevented; to avoid this use the clear() method.

True. So what error are you expecting that needs to be cleared at this point?

I guess you're probably suggesting that in this particular case it's not needed. Looking at the code I can't see how a mis-match of data cin >> ch could occur and I don't think EOF is an issue either. I hope I haven't embarrassed myself with this answer or response.

That's what I'm suggesting, yes. And you have definitely NOT embarrassed yourself. It's a correct analysis.

Taking this a step further in relation to cin.clear(). If the receiving variable is of a numeric type is that when cin.clear() would be considered in fixing up erroneous data entries.

Actually, no. All cin.clear() does is clear the error flags. If they were set, it does not fix any data entries. The way you're using it, the error is simply cleared and ignored. You never test for one, so you don't even know it happened.

What you suggested above is "If the receiving variable is of a numeric type" and you type in a letter instead, cin.clear() magically changes the letter to a digit. What in fact happens is the error flags are set, nothing is loaded into the variable (previous value remains unchanged), and the letter stays in the input stream for the …

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

Thanks for the advice, very much appreciated. I've altered the code as suggested and is a lot 'cleaner' looking.

Not bad, although it's still not formatted properly.
By the way, what does cin.clear(); do? You might want to look it up.
Another thing to look at is system("PAUSE"); See this

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

int *buf declares buf to be a pointer to integer.

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

I also used the

while(!=feof(in))

you had suggested, the reason I was reading it twice was to find the length but using your suggestion I just added a counter to get over that and just read it once.

I would never suggest while(!=feof(in)) !!! See this and you'll see why.

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

Please learn to format your code better so we can read it. Pay attention to the Indentation section.

Look at the parameter types in the function call you're having trouble with. What are the variable types the function expects, and what are the variable types you are passing?

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

52 C:\Users\Desktop\coding.cpp initializer-string for array of chars is too long

This one is quite obvious. How many characters are you trying to stuff into what size array? Remember, c-strings must end with '\0'

C:\Users\Desktop\coding.cpp:83: error: `clrscr' undeclared (first use this function)
C:\Users\Desktop\coding.cpp:92: error: `sleep' undeclared (first use this function)

Where did you define these functions? They are not part of standard C++.

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

The SPACEs in the scanset seem to be the problem. Remove them and see if that works for you.

Also, check out this information on
main()
while (! feof(in))

And what is the purpose of reading the file first? Just read it once.
I would also suggest rather than using fscanf() you switch to fgets()/sscanf() combo. If an error occurs with fscanf() it's harder to recover.

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

Why would you type forum when there's more than one? :?:

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

Is using '#' to deliniate lines required by the assignment or is it something you dreamed up on your own?

while( cin >> name >> street >> city >> state >> zip)
{

}

Will that work for:
John Smithers 2031 West Alberta Street Sioux Falls South Dakota 65565? What will be in zip? :icon_rolleyes:

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

Are you in fact asking us to tell you what you are doing wrong? If so, how would we know? We aren't the Psychic Programming Forum.

Have you considered showing us what your code is and explaining
1) what is actually happening and
2) what you want to happen?
Like the post titled Read Me: Read This Before Posting says? (note the title -- it's important) Please do so and we can probably cut this from a three day guessing game to a 2 hour solution session.

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

How can in "play havoc" when 0.0000517 is almost 0.00? They are essentially the same. I suggest it's how you are using 0, not the fact that it's a minuscule number.