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

Open the input file
Open the first output file
Read a line
Count it
Write the line
Read a line
Count it
Write the line
Read a line
Count it
Write the line
-- when the count gets to one of your magic numbers
Close the output file
Open the next output file
Continue reading, counting, writing...

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

Add another getline() just before the return in main....

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

Look up the MID, LEFT, RIGHT and INSTR commands.

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

[boilerplate_help_info]

Posting requests for help must be well thought out if you want help quickly and correctly.  Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful?  Check your post with these checkpoints - what is it [i]you[/i] missed:
[list=1]
[*]Ask a question that can be answered. Do not ask
- What's wrong with my code?
- Why doesn't this work?
- Anything else that does not give us useful information.
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- see this
- Use CODE Tags so your formatting is preserved.
If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
[*]If you have errors, post them! We can't see your screen.  We can't read your mind. You need to tell us what happened.
[*]Do [b]not[/b] ask for code. We are not a coding service. We will help you fix your code. 
    If anyone posts working code for you, they are a …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Ever hear of arrays?

How do you expect to debug a statement like

while(a<1 || a>16 || b<1 || b>16 || c<1 || c>16 || d<1 || d>16 || e<1 || e>16 || f<1 || f>16 ||g<1 || g>16 || h<1 || h>16 || i<1 || i>16 || j<1 || j>16 || k<1 || k>16 || l<1 || l>16 || m<1 || m>16 || n<1 || n>16 || o<1 || o>16 || p<1 || p>16);

and at the same time notice that one error is the ; at the end?

You need to use the KISS principle, and a separate variable for each value is not it.

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

if(strcmp(s.name, stdname)==0)
is this statment is correct? i am having an error while executing this statment.. i have givn its headerfile

Depends on how s is defined.
Depends on how name in s is defined.
Depends on how stdname is defined.
Depends on what headers are included.
Depends on what the error is since there are hundreds of error messages possible.

As it is, the statement is syntactically correct.

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

Portable doesn't have anything to do with the .EXE file that's created. It means the code you write can be built using any C++ compiler.

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

No. You obviously didn't bother to read the link I posted.

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

To clarify what DJSAN10 is saying, assuming it needs clarification, in each IF block you are creating a new lettergrade1 which gets destroyed as soon as that block ends. The lettergrade1 value at the top is never used.

Kudos for using the 'proper' IF-ELSE construct and not using else if (s1score >= 0.70 && s1score < 0.80)

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

Please use proper formatting techniques, especially on indentation. See this and repost.

... But, I learned a valuable lesson that day, why it is very important to write maintainable code. That first hand experience of dealing with my own unmaintainable code has changed my coding style forever. I cannot emphasize enough, how important it is to learn proper formatting skills, learn from my mistake. I hope you find your bug.

Apart from the fact that it's hard to see what's going on because of the lack of indenting in you post. If the code looks like this on your own computer, then I would expect you to be having problems figuring out what's going on!

White-space can be used to aid readability further (as above). It might not seem like any of this is that important, since the compiler doesn't care about it. However, it's vital for the readability and maintainability of your code.

3 different people, same comment. And you are ignoring each of them! Why should we bother?

FORMAT YOUR CODE!

I suggest no one bother trying to dig through his code anymore if he's not going to bother listening. It'll take 10 minutes to format that mess properly, and save us buckets of time trying to be nice helping him for free.

And stop QUOTEing your text. It's not a quote. Just type it in.

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

One last comment about yours: what happens when the user hits the RETURN key or Ctrl-D after just inputting the month and day? Is the year still sane?

Yes. Because, since you are discussing best practices, when you test the return code from scanf() you will find all values were not entered and handle the improper input. You do advocate always testing the return values from all functions, don't you? :icon_wink:

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

1. Initialize ALL variables to sane values (if only 0 or NULL) when you declare them.

Unnecessary. Only values that are not read in or set in the code need to be initialized. In your example

int mm = 0, dd = 0, yyyy = 0, mm2 = 0, dd2 = 0, yyyy2 = 0;
   
   printf("Enter first date (mm/dd/yyyy): "); 
   scanf("%d /%d /%d", &mm, &dd, &yyyy);

initializing mm,dd,yyyy are completely unnecessary and a waste of time.

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

Now that you've figured it out, go back and up-vote more of my posts! :icon_twisted:

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

Thanks WaltP. I didn't know that. I posted it with the knowledge that int i = 09; gives an error.
So, I believe scanf will be doing some formatting to 09. Am I right?

No, scanf() reads in what you type into %d (decimal). 09 is valid decimal. It's only the internal use that a beginning 0 indicates octal.

On the other hand, you are correct if you use %o in scanf() .

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

you should use flag and store 1 if 1st date is smaller.and use break; in if block;

Have you ever used a break in an if() block? It doesn't work.

I don't see any validity checks done for your dates. He can enter invalid dates like 33/33/2012.

I would assume validity checks in this program are moot. It's just to figure out how to compare dates in general

day1 = yyyy1 * 10000 + mm1 * 100 + dd1
day2 = yyyy2 * 10000 + mm2 * 100 + dd2

Check which is greater out of day1 and day2. So simple, isn't it :P

Nice. Simple and workable, even with invalid dates. I'd use some parentheses though. Makes the equation easier to read.

But there is another potential error in your program. Your variables mm1, dd1 are declared as integers and in your console out put you ask the user to enter in mm/dd/yyyy format. So for September, the user will enter "09". But since mm1 is declared as int, "09" will be treated as octet number and you'll get run time errors, since 8 & 9 are not allowed in octet system. So better use strings.

Completely untrue. Write a test program and see.

subith86 commented: thanks for the info +3
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Please use proper formatting techniques, especially on indentation. See this and repost.

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

Sorry, I'm confused..

matrix = new double[(unsigned int)rows*(unsigned int)columns];

Is 2D right?

e.g.

matrix = new double[10][20];

No. Get rid of all the unnecessary stuff in the line and you get matrix = new double[rows*columns]; Where's the 2D in that? Count the square brackets...

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

Bingo! I told it was for a mod, Well it was about you. I tried up-votes two times(Not consecutive) and they just disappeared... It only happened with you so-far...

The system obviously doesn't me to get a swelled head. I'll start leaking brain all over the keyboard...

And tried up-voting two of your posts today, it worked.

Yay! Bigger rep numbers! I feel the swelling!!! :icon_mrgreen:

jonsca commented: That's just a pimple.... +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I've found the UP/DOWN arrows to be flaky at best. Though they don't disappear for me most of the time, when I click one half the time nothing happens.

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

I think you're going to have to wait for someone from India to join the board that can help since it seems only India teaches with outdated equipment and tools. The rest of the world left Turbo-C over 10 years ago.

And Narue wasn't joking... :icon_wink:

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

it is simple:

Then why make it so complicated? How about:

#include <iostream>
struct Point             // use proper formatting
{   
    int X;
    int Y;
} ;
typedef  Point* PointsArr;

int main(void)                      // use proper main() footprint
{
    PointsArr test[10];             // hold 10 points
    for(int i = 0; i < size; i++)   // use whitespace to more easily read the code
    {
        test[i].X = i * 2;          // use whitespace 
        test[i].Y = (i * 2) + 1;    // use whitespace 
    }
    for(int i = 0; i < 10; i++)
    {
        std::cout << test[i].X << " " << test[i].Y << std::endl;
    }
    return 0;                       // end main() properly
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Nowhere do you properly test for valid input.
In the loop

for(j = 0; j <= strlen(input); j++)
{
    if(input[j] == ref[i])
    {
        run = 1;
    }
    else if(input[j] != ref[i])
    {
        run = 0;
    }
}

you give it a try, but if the last character tested is good, you set the entire input to good. Follow that code with pencil and paper.

In the line status = scanf("%s", input); you
1) return a status but never test it where it does any good.
2) read only up to the first whitespace, so an input of "2 A +" only reads "2".
3) Read this.

Here's the secret to solving most of your errors immediately: printf() !!!
Print values to see what they are at key spots in your code. Displaying input immediately after your scanf() would have shown you what your major problem is.

Also, proper formatting will help a lot in readability. Concentrate on better indentation.

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

That it could contain anything?
The reference I'm using says strcat will append string2 to the end of string1, so we add a string terminator to the beginning of buff, to make sure strcat will write from buff[0], even if other elements contain a terminator. So yes, buff[0] = '\0' is necessary.
Guess I could figured that out : )

And you did, too! :)

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

If "malloc() doesn't guarantee anything about the data it returns a pointer to" what do you think that means about your buffer?

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

Just load the new string into Text1.Text

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

#1) What zeroliken said
#2) It's C++. Why are you using the terrible and dangerous C function gets() ? Use getline() .
#3) cin is your problem. Reading an int leaves the NEWLINE in the input buffer. The solution has been explained many many times on this site -- do a search.

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

Hello,

I do not understand the following parts in bold - how it works, what is is for..etc. I'm not following the book's explanation..

It called a prototype. If you use the function (line 17) before you define the function (line 30) the compiler does not understand line 17. Therefore, you add the prototype to tell the compiler "when you see this function, it's used like this way -- it will be fully defined later".

It's like a trailer to a movie. Lets the compiler know what it's about.

I'm also not sure why it's called "parameter" here. Like I said - basically, I can't figure out why it's there and what it exactly does. I would appreciate any help.
Thank you

Why what's a parameter? Maybe it's called that because that's what they call it. Like why do they call it an airplane -- because that's what it's called.

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

Is there a simple way to catch the char input and ask the user to fix his choice, similar to the way my program handles a user entering a number that isn't in the menu?

Read all your inputs as strings. Test the string for all digits. If correct, convert the string to a value and continue.


[minor rant]

Be gentle. I'm a noob. ;(

This is and always has been one of the most obnoxious requests we get. What makes you think we can't tell you are a noob? Doesn't your question already implicitly state it? :icon_rolleyes:
[/minor rant]

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

First is contact the person to understand why.
If you still disagree, flag the post as bad and explain why you want a change.

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

If you say so. Although they might be able to explain why if you are unable to grasp the comment. Or they could give good rep to counter the bad if you're argument is sound.

And if you go through the right channels, the rep can be reversed/removed.

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

You could PM the commenter. But be careful. Don't do it too often.

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

My question is. how do i calculate the prime factors like if I enter 30 the response will be: 2, 3, 5.

I have a program that works using recursive functions but the exercise is asking to modify it without recursion.

1) Throw away the program that uses recursion.
2) Figure out how to calculate the prime factors on paper.
3) Write down the steps used. Test the steps with many values.
4) Convert those steps into code.

Do not skip any of the above steps. Especially #3.

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

Try removing the comment indicators at the beginning and end of the code. It might compile better.

Help in what? You have to ask a question in order to get help.

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

wonder if there is a way to just not allow certain words in the subject line? (help, urgent, ect..) im also not versed on websites (barely understanding vb) but, just an idea is all (and not really sure if its a good one LOL)

What part of

Hold your suggestions for just a bit longer :)

did you not understand? :icon_rolleyes:

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

With what?
Formatting? OK, here.
Stopping the program from inside the function? Don't. It's a bad practice. Return a value that indicates what to do in main()

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

thus: 405678
step 1:

405678 / 16 = 25354.875.. take 0.875

25354 / 16 = 1584.625... take 0.625

1584 / 16 = 99.0... take 0.0

99 / 16 = 6.1875... take 0.1875

6 / 16 = 0.375... take 0.375

Why do it the hard way? Just do the same procedure as in the code, combine step 1&2:

405678 mod 16 = 14
25354 mod 16 = 10
1584 mod 16 = 0
99 mod 16 = 6
6 mod 16 = 6

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

My main problem is your lack of consistent formatting and really deep indents. It makes the code very difficult to follow. See this for better formatting techniques.

annonymous21 commented: Reply has no relevance to my post and was not helpful. +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

In main() you use 2 to convert to binary, correct? What would you use for hex?

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

The aim is simple: Input a string from the user, input a word that is to be searched in the string, and return "Found" or "Not found"

I have worked down the following code, and it works.

#include <iostream.h>
#include <stdio.h>
#include <string.h>

void main ()
{
	char para[200], word[20];
	int i=0, c=0;
	
	cout<<"\nEnter a paragraph: ";
	gets (para);
	
	cout<<"\nEnter the word you want to search: ";
	gets (word);
	
	while (para[i]!='\0')
	{
		if (para[i]==word[c] && word[c]!='\0' && para[i]!=' ')
		c++;

		else
		c=0;
		
		i++;
	}
	
	if (c==strlen(word))
	cout<<"\nWord found"<<endl;

	else
	cout<<"\nWord not found"<<endl;
}

I want to do it without having to use the strlen() function but I'm clueless. I don't want to use any library function for the search of the word in the string.

Edit: I could also count the number of letters in the character array 'word' and store it in an integer, then compare c with that integer, instead of using strlen().

Is there any other entirely different approach for achieving this?

1) Read this about void main() .
2) Read this about gets() .
3) Just use a loop to count the characters in word up to the \0.

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

So, what the heck, I might as well try playing around with some code. I'm bad at C++ anyway so I could use the extra familiarity with it.

So why would you want to familiarize yourself with something that cannot easily be done in C++, is very compiler specific (it won't work on most compilers), and is not part of the C++ Standard?

IMO, you'd be better off dealing with problems that utilize the language as it's designed rather than using hacked-together code.

I think a Monopoly Game is a good idea, just wait on all that fancy stuff until you know the language well enough to add a GUI package. Design all your output and input as functions that can be replaced with calls to the GUI later.

Just my 2-cents.

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

Just look in the .lnk file or right-click and select Properties. Then copy the location right out of the link file and put it into your 'launch' program. Then you don't need all this Rube Goldberg crap.

An .exe to call a .bat file to call a .lnk file to open a program? Get real!

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

sorry i should have made my post more descriptive about what i didn't understood,

Yea, you should be clear and concise.

this is in my class book about command like parameters, i asked my mam to exaplin it but she gave vague answer also this thing doesnt clearly explain about argv, argc and what are command line parameters used for.

Yes it does. It's not the greatest explanation, but it is a correct, and accurate description of the parameters.

It is actually your explanation of the problem that is vague. What is it you don't understand? What phrase or explanation is it that confuses you?

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

Here is another description you can read and maybe not understand. And if that's the case, you need more basic knowledge before you can understand the complexities of command-line parameters.

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

i must be going out of bounds for the array text.

In your first code, why are you using new to get temp then you delete ret?

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

Sorry, I'm not reading code that isn't formatted. See this.

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

in the 2nd code, the int i is not defined in the main(), so, because of that, we can use multiple 'for loops' with same iterator(int i)?

Why can't you use i in multiple FOR loops if i is defined in main() ?

unlike 'while loops', the int i declared in the main(), so we can't do the same as the 'for loops'?

What can't you do the same? What's preventing you from using i in the WHILE loop and FOR loop?

can anyone confirm of what I "discover"? :)

I'm unclear what you 'discover'? Unless I misunderstand you most of what you're saying is wrong.

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

Why are you decrementing then incrementing the loop counter in the FOR loop? You should not touch the loop counter...

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

Hello.
The title pretty much says it all.

Don't use the title as part of your problem description. The title is only to evoke enough interest for us to click on the thread. Then it's forgotten...

I would like to know if and how you can print a number (type is double) with the same amount of decimal spaces as the one you entered.

Read the number as a string. Count the decimals. Convert the string to your double.

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

What's wrong with the standard form:

int change (int k)
{
    if (k==1) k=0;
        else  k=1;
    return k;
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Hi,

Yes, Client_ID's should be Unique.
But still if, you want to renumber them, Change your code to :

Public Sub generateid()
    Dim i As Integer
    i = 1
    If rs.State = 1 Then rs.Close
    rs.Open "clientdetails", admincon, adOpenDynamic, adLockOptimistic
    Do While Not rs.EOF
       rs("Client_ID") = i
       rs.Update
       i = i + 1
       rs.MoveNext
    Loop 
End Sub

Regards
Veena

But what about all the other database records in the other tables that have the ID in them?