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

the array size, i, is supposed to be 271.. i set x = i-1 //270, the last index for cout...... and then i-- ,,,, up to 0....... i don't know why it doesn't read or display from the beginning of the txt file eventhough if i test with a code like id[0] or lastName[270] , they will give me the right index value

"Supposed to be" is evil. Never assume. display the value in both loops and be sure.

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

Hello,I am new for C++.The following are the codes I wrote to calculate the sum of 2^n. The result is 2046 after running the program.That is correct. But when I change the condition to n<=100,the result comes with -2,which is obviously wrong.Then I tried different n and found if n<=30,the right result can be obtained but if n>=31 the result is always -2.Can someone tell me where my mistake lies and how I can solve it? Thank you.

You don't have a problem, just lack of knowledge, as described by VernonDozier.

You're probably going past the bounds of what an integer can store and getting an overflow. An integer in a 32 bit system overflows at 2^31, I believe. It cannot hold anything higher than that.

This is exactly what the problem is...

please wrap ur code

In what? Saran Wrap?

i think use a long

int and long are identical in most compilers today.

Use link list to represent big number else overflow will happen.

Did you miss the first 6 words of the OP's post? And linked lists don't fix overflows.

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

but will my code work if i enter one single digit?

What happened when you tried it? You are basically asking us to write your program for you.

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

Where is your attempt at it? You should know by now we won't do the work for you.

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

n what abt the declaration of 2d n 3d array n how to call them

Plz rd ths abt prpr pstng so ppl cn rd wat u wnt hlp wth...

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

And in simpler terms...

1D array: The list of TARGET stores in one city.
-- Store numbers 1,3,5,7,9 in Detroit

2D array: The list of Target stores in each state by city.
-- in Michigan:
---- 1D array for Detroit
---- 1D array for Pontiac
---- 1D array for Lansing
---- etc

3D Array: The list of Target stores in each country by state by city.
-- for USA
---- a 2D array for Michigan
---- a 2D array for New York
---- a 2D array for Oklahoma
---- etc.

4D Array: The list of Target stores on each or each planet by country by state by city.
---- 3D array for USA
---- 3D array for Australia
---- etc.

and so on.

:icon_wink:

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

Use you command promt and run. Or if you want to run it directly add std::cin.get() at the end of main() to wait for a keystroke. However this wont work under certain circumstances as mentioned here.

Actually, wait for an ENTER :icon_wink:

Was that first post meant to be a Haiku or something ;)

More like a non-rhyming limerick -- 5 lines :)

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

i saw the libary there are a few commands like biascom in bios.h, i feel that will do the job of getting the values from the serial port.

but how do i transfer it on to a test file??

First things first. Read data from the serial port. Don't try to do the entire program in one shot. Once you get the reading part running, then consider writing to the file.

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

Look up the function time() and it's friends.

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

To explain what Wee is telling you...

Loose the '' around the numbers. i.e '2' becomes just 2

You don't need to loosen anything, you need to lose something... :icon_rolleyes:
'2' is the ASCII character, 2 is the number. You need to compare the number 2, not the character. Same with '1'

Oh and the = should actually be == in the if statement.

= is the assignment operator, == is the comparison operator. Therefore, if (number_of_scan = '1'){ actually assigns the character '1' to the variable.

Also, see this about formatting your code so it's easier to read.

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

Of course there's output. You have cout statements in your code. Unless you're not telling us the whole story. Explain exactly what is happening, and why it's wrong. Examples are easier for us to understand.

And about "I WANT IT FOR TOMORROW" -- we don't care. You should have posted last week if you needed that bad. See this, it's in The Rules you read when you registered.

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

since printf() is a c function I can;t understand it :)

Sure you can. It's obvious if you think about it.

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

Hey guys, the OP said

i can't find what i have to do so that my c program increments my counter by 1 it has to find and empty line.

The definition of a paragraph is not ambiguous. He defined it.

Comrade Ogilvy commented: I thought so, too. Thanks. +1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

My hint #1: Use a better title. Something like Creating a Date Histogram. Also, Read This

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

121 posts and you still can't make a proper title? And you should know by now most of us won't help without posting code, nor will we download it.

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

I have a project on ATM machine,and i want to enter the account NO,passwprd , opening Balance etc. in the text file from the user (using "cin") and save that record in text file.

And your question is....? Since your statement mentions the very basics you should have already learned, you should be able to do at least the input portion.

Have you read any of the recommended posts? We do not write code for you. We help you with the code you write.

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

Problem #1: Your title. See this

can we send the input from command prompt screen ...

Problem #2: A command prompt screen does not contain input. A screen is an output device.

....to the text file in C++

Problem #3: C++ does not contain a text file. C++ can read a text file, but a screen is not a text file.

....to the text file in C++ if anyone know plz tell me about it briefly

Problem #4: Is there supposed to be a period (.) somewhere in that sentence? We do like to be able to understand the questions posted, so please try to post understandable questions.

So please rethink how to ask your question and try again.

And about plz, see this

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 also used it in assembly language the code was 0dh,0ah...someone asked me what does each byte mean? please explain!!

0Dh is carriage return. Return to the beginning of current line.
0Ah is a line feed. Drop down to the next line.

In assembly you don't have the luxury of '\n' which does both.

wouldn't that be an in-efficient way??

Somewhat. But it's safe and easy. Trying to change the file on the fly is dangerous, and if you have to add just one extra character, it cannot be done without screwing up the file.

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

I believe you are using the wrong index in the line if (random_integer > running_total[i]) Shouldn't that be running_total[B][j][/B] ?

Also, please work in your formatting consistency. Your code is just a little difficult to follow. See this.

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

Examples

1100100101001001
        11111111
----------------------
00000000[B]01001001[/B]
buff gets 01001001

1101110110110011
        11111111
----------------------
00000000[B]10110011[/B]
buff gets 10110011
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I would let the OP post his code before writing it for him...

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

hehe i was expecting this...:icon_lol:
well he showed his program....so i just posted the code...
he showed his efforts atleast..so just did it..

And rather than learning something useful, he learned he can post any thing and get the code to hand in from someone else... :icon_rolleyes:

Please help them, we know you can write it. They're the ones that need to learn.

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

write a function for factorial and sum its digits and check for equality...it's simple..isn't it???

do u want a complete code??
if yes then sorry..nobody will help you here for that...

Good point.

...
this function returns sum of the factorials of all the digits of a given numbers sent in c
...
this will print all the numbers less than n which are special...

What happened to your previous post? Did you forget?

darkagn commented: That's exactly what I thought :) +1
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

hello i have changed my previous code about converting a statement to reverse polish notation but still i think it has serious problems .can any one help me solve it? i have just a little time!

You think you have a problem? What makes you think so? Have you read the post Read Me: Read This Before Posting yet? The title says it all.

Also, you need to format your code. See this...

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

And stop making multiple threads on the same stupid with the same stupid title. Please read the RULES.

Salem commented: Yeah, you tell 'em! +12
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

the errors is liek this
17 C:\Dev-Cpp\main3.cpp expected constructor, destructor, or type conversion before '<<' token
17 C:\Dev-Cpp\main3.cpp expected `,' or `;' before '<<' token
C:\Dev-Cpp\Makefile.win [Build Error] [main3.o] Error 1
and sorry for making quotes tags,where is the CODE tags ?

[code] at the beginning, then [/code] at the end

Where's your int main() declaration? Go back to your book and reread the section on basic program structure. Use the Hello world program as a guide.

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

You have to format the stamp yourself from the information received from the functions Ancient Dragon suggested you look into.

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

i want c++ ...can u write the code please ...i need it urgent

Did you fix the errors? When you do, repost and ask questions. Do NOT ask us to do your work for you.

And stop using QUOTE tags when you need CODE tags.

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

Hmmm, badly formatted code.

Anytime we see

}
}
}

we know we're not going to be able to follow the code easily. See this and format your code properly. And please don't post code without some kind of explanation. New people can't necessarily understand uncommented code without explanations.

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

[aside] I'm mighty popular all of a sudden, that's really flattering[/aside]

Yeah, but it's generally not the type of popularity that's healthy...

Those type of comments are written in such poor taste. Something should really be done about that, as I'm sure if that were an actual post, a warning would be issued from Admin at the very least. It makes me quite sad :(

You complain about taste? The mind boggles? What's this world coming to?

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

When you read file in C and move to next line and so on. This seems you have to access file top to bottom sequentially without skipping lines.

I need a way to read very 5th line or something similar to it. I am just concerned with data that is present very 5th line. So if I start with line 1, then next line I want is line 6 and so on.

Would I be able to achieve this kind of file reading?

Read 4 lines, process the next. Read 4 more, process next.

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

This happens because new posters like Knightzs are not fully aware of the rules over here.

And why is that? Aren't the rules clear? :icon_wink:

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

I need help with beginning code to simple game of hangman in C++
Don't know where to start and it is due in six hours.

Start with ignoring the code jaepi pointed to. It doesn't work, and it's not that great.

Did you miss reading the post titled Read Me: Read This Before Posting and the Rules?

To quote the sign that I've seen in offices for the past 30 years

Poor planning on your part does not constitute an emergency on my part

You should have done something much sooner than 6 hours before it's due.

Anyway, array 1 should contain the message to be guessed.
Array 2 should start out filled with _'s for each letter in the message.
For each letter guessed, the letters are filled into this array in the same positions as the message array.
When there are no more _'s in the guessing array, all the letters have been guessed correctly and the player wins.

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

You are attempting to read a single character, right?

When you enter that character, what key(s) to you type? The character and ENTER, right?

Well, the ENTER is also put into the input buffer, but when you read a single character, only the first character was removed from the buffer. The ENTER is left for the next input.

The same happens when typing numbers. The numbers are read and the ENTER is left.

So here's what is happening. With this code (please note how the code looks when you use CODE tags as The Forum Rules recommend -- you must have missed that when you read them after registering :icon_wink:) :

printf("enter 2 nos :");
scanf("%d %d",&a,&b);

printf("\nenter your choice:");
ch=getchar();
printf("%c",ch);

Here's what happens:
Display message "enter 2 nos :"
You enter for example "2 3[ENTER]" -- note that is 4 characters, including the SPACE scanf() reads the two numbers like this
a) '2' is read, converted to integer, and loaded into a
b) Whitespace is ignored (SPACE is skipped over) and the 3 is loaded into b
c) ENTER is left in the input buffer.
Display message"enter your choice"
ENTER is read by getchar() and loaded into ch.


Your next attempt is:

printf("\nenter your choice:");
ch=getchar();
printf("%c",ch);

printf("enter 2 nos :");
scanf("%d %d",&a,&b);

Here's what happens this time:
Display message"enter your choice"
You enter for example "x[ENTER]"
'x' is …

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

In strings, the \ character is the first character of a pair, like \n, \t, etc. If you want a \ in a string you need to use \\.

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

You should scrap this code completely.

You need to look into the values of characters. For example, the letter 'A' is the same as the integer value 65.

Run this program and see the correlation between characters and numbers. Then think about your idea with this information in mind.

#include <iostream>
using namespace std;

int main()
{    
    int i;
    
    for (i=32; i<126; i++) 
    {
        cout << (char) i << "  " << (int) i << endl;
    }
    
    return 1;
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I tried the following way and it doesnt work:

if (cbuff[0] == '#' && cbuff[2] == 'N' && cbuff[3] == 'a' && cbuff[4] == 'm' && cbuff[5] == 'e')

Instead, how about

if (strncmp(cbuff, "# Name", 6)

Next:

strncpy (name, cbuff+8, 6);
name[6] = '\0';
strcpy(filename, name);
strcat(filename,"_TAUTOMER_");

Simplify:

strncpy (filename, cbuff+8, 6);        // Copy the first part of the name
strcpy(&filename[6], "_TAUTOMER_");    // load constant into place

And for the rest, you're close:

fidx = strlen(filename)    // get the number of characters in filename
while(cbuff[i] !='\0')     // loop until you get to the end
{
    if (isspace(chbuff[i]))
    {
        filename[fidx++] = '_';    // load an underscore for a space
    }
    else    // the character is not a space
    {
        filename[fidx++] = chbuff[i];  // load the character
    }
    i++;           // next character
}
filename[fidx++] = '\0';     // make the filename a string
strcat(filename, ".mol2")    // finish off the filename

This might be closer

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

Then you need to look up how syslogd works. Google for it.

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

>>pim.cpp:106: parse error before `.'
You can't pass in pim.contacts[] , only pim Start with that.

Also when you post the errors, be sure to specify which line number in the posted code is the line number in the message. Your numbers were off by 10 for some reason.

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

WaltP I am pretty curious to know now, how would you make OS to log things for. As far i know it should have done by programmer itself isn't Or... am i going wrong somewhere

Only in your explanation. You said "I have a C program I am writing and need this program to write to syslog..." Syslog means system log, the log file for the system and I was simply wondering if you really meant what you said.

When you need to log a message, call a function that uses sprintf() to put the message together. Open the file, write the message, close the file.

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

DevC++ works for most people here. Are you absolutely sure your code compiles without errors?