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

Just another suggestion how you could do it.. (No need of using do while)

while(1)
{
  if(...)
  {

  }
  else if(...)
  {

  }
  else if(...)
  {

  }
  else
     break;
}

This is a terrible suggestion.
A while loop is designed to exit when a condition is met, which is exactly what the OP's loop needs to do.

There are some programs that can legitimately use an endless loop as you described it, but don't use one just for the fun of it. Use the commands as designed except where necessary.

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

I used google trying to find what is the easy way to implement the ubiquitous "Hit any key to continue." in a "console" app (I'm using Visual Studio 2010 atm).

I found the answer above, thank you DCX2. Here is the 2010 version of the answer:

http://msdn.microsoft.com/en-us/library/58w7c94c.aspx

Microsoft: "Use the ISO C++ conformant _kbhit"

(You have do do something like:

while( !_kbhit() );

)

Could you please state the passage in the C++ Standard that claims _kbhit() is in any way compliant. Include a link to the copy of the C++ Standard you used.

Just because M$ has implemented _kbhit() does not mean any other compiler has. Please list a few compilers that also include _kbhit() in their runtime library.

And _kbhit() inputs nothing. It cannot implement a "press any key" in any way. To claim it does only adds to the ignorance of the previous posts made about it.

[o.t. rant]
Since this thread has already been thoroughly trashed by people more concerned with showing how much smarter they are than the other poster [implicitly bringing themselves down to their level]...

Including yourself with even more incorrect information... :icon_rolleyes:

... I must address a particularly irksome point:

> "It's generally considered rude to resurrect ancient threads, for any reason."

NO! To anyone who says that, please stop it already!!!

I have been reading the Internet since about 1987. That general idea about posting to "old" threads being bad has to be one of the …

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

That's because you didn't add the chr(34) .

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

Use getch() function defined in conio.h thereby you can avoid using scanf() to hold the output screen.

Very bad suggestion. getch() is
1) not portable
2) not Standard C
3) defined in very few compilers
The appropriate function to use is getchar() because it is
1) portable
2) Standard C
3) defined in all compilers

But his this case neither solution will appear to work since the NEWLINE from the last input is still in the buffer waiting to be read.

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

Add chr(34) to each side of the string. 34 is the value for double quote.

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

okies! see it now! first c is checking that if the character is a space. if it is so, then,i am storing at which place my pointer was that at that time because i need to come back at this later on.as after reading one character pointer shifts by 1, so by fseek, i am shifting it to character which is just adjacent to the space(assuming space given between each word is 1).then i am taking my pointer back till previous space come back(as this tell that word ends here).after fseek, then i am reading each character till space and writing it to the other file .and again with fseek, i am shifting pointer 2 steps back because it shifts forward but i need to move backward.so when i read space again, loop ends. and the position which we have stored earlier is used to make the position of pointer back. and that's how loop is going till end of file is there.

What a convoluted piece of illogical code.

Read the characters.
Put them in a buffer.
Use the buffer to do all that crap. Don't do it in the file!

If you get a non-space, add it to the buffer.
If you get a space, your buffer contains a word.

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

Try

cout<<"Name:"<<endl;                    
    std::getline(std::cin, name);
    cout<<"Phone:"<<endl;
    std::getline(std::cin, phone);

Mixing line inputs (fgets/getline) with cin is causing problems because they both do things differently. cin is leaving the input stream dirty (stuff left in the buffer you aren't expecting).

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

My mistake...

There should be a new-line after the brace. The brace should be on a complete line.

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

Is there a NEW-LINE after the last }?
Sometimes that causes the error.

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

Please explain what this section of code is doing and why? Line by line...

if(c==' ')
           {
                   x=ftell(p);
                    fseek(p,-2L,1);       
                           while(c=getc(p)!=' ')
                           {
                                 putc(c,p2);
                                 fseek(p,-2L,1);                          
                           }
                           
                           putc(' ',p2);
                           
                        //   fseek(p,x+1,0);
           }
           fseek(p,x,0);
           l=ftell(p);
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

We can't see your screen to see what the code looks like now.

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

This is again one of the stupid ways of spammers out there who want nothing but money from you, when you will contact them they will have some false sob stories with some pictures that are very difficult for a normal person to view..

From experience, I assume? :icon_twisted:

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

Read Profession by Isaac Asimov. Maybe you're asking the wrong questions...

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

2 resurrections of a 7 year old thread with "give me the answer" posts show this this thread is a lazy-student magnet.

Closed

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

No. In order to read the 5 you have to hit ENTER.

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

No, it's because of undefined behavior. See this

DJSAN10 commented: hey thnx.. +3
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Lots of problems in this code...

#include<stdio.h>
#include<conio.h>      // unnecessary, non-standard -- should not be used
#include<stdlib.h>
#include<string.h>
#include<time.h>

void main()           // MAIN is not and never has been a 'void' -- see below

{
	int i[100];   // create an array from i[0] to i[99]
	int j[100];
	int k;
	int m;
	clrscr();     // unnecessary, non-standard -- should not be used
	printf("Enter the number of questions needed:");
	scanf("%d",&m);
	if (m<=100);
	{

		i[100]=rand()%m;      // I only goes to 99 -- 100 is not part of the array
		printf("%d \n",i,rand()); // calculate and print a new random number. Among other problems.

		j[100]=rand()%m;      // see 'I' above
		printf("%d",j,rand());

		i[100]=rand()%m;      // You are replacing the value above
		printf("%d \n",i,rand());

		j[100]=rand()%m;      // same
		printf("%d",j,rand());
	}


	getch();  // non-standard -- should not be used.  GETCHAR() is made for this
}

void main() -- See this

I want to generate random numbers when I press the amount. i.e. If i enter 50, then it should generate 50 random numbers between 1-100.

How can you generate 50 values without a loop? You only generate 2 values for each array, and don't even store them in the arrays.

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

let me know what flush(stdin) describe.
is ti any kind of function or something else...................
try resolve my problem

flush(stdin) describes something that knowledgeable programmers would never use. See this

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

Sorry but I'm not very good at explaining...

Then why don't you post an exact example of what you want the output to look like? It's always easier to show than explain, although both are important.

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

Look it up in your textbook.

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

Don't use gets() Here's why.

What he's saying is
1) Input the information as a string with

fgets()

2) Test each character to make sure it's all digits or 'EXIT'
3) If all digits, convert to integer with

atoi()

can you maybe translate that into a code since I don't really get what you're saying. sorry I'm new to this :(

Try it. Don't ask us to do it for you. You learn more when you do it.

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

Try Googling for permutations so you can learn the basic algorithms.

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

90% of all other languages are derived from C.

Really? Maybe you should check out this list and pick out the 10% that are not a C-derivative. Or better yet, pick out 10% that are! :icon_rolleyes:

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

Its not my first code posted to a website ever... Im a newbie on this website... Not web posts forums and codes.. I know how they work..

But you don't seem to understand the community, only the basic operations of forums. Try to understand the community before you start arguing with people about the way things are done. Here we attempt to to help people with quality information, not bad information based on, say, 20 year old Turbo-C knowledge and other non-Standard practices (that's the C/C++ Standards).

We also frown on new members telling us we do things wrong without knowing why we do things the way we do.

Just a heads-up.

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

I would write a few test programs that manipulate bits so you can understand what bit-shifting, ANDing, and ORing is all about. Then when you understand these basic principals, go back to your program with your new understanding.

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

Sorry man... I got pissed wid dis thread getting bumped when its problem was solved.. Theres other stuff to deal with than rather keep seeing the same solution.

You've been here less than 1 day and you had to bump a thread you got pissed at because of useless bumps? You've got to be kidding!

Whether i write closed or some1 else does, the point is the person has solved it and needs no more help! Does that really matter WHO writes it? Pls dont get ego involved..

It's a Moderator's job to police the boards an point out stupid posts like that so they aren't made next time. No ego involved. Unless you consider that after 15 posts you know the boards better than a Moderator that's been here for over 7 years. That sounds like ego to me...:icon_wink:

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

Great... Pls include code next time

----------------------------- Closed ------------------------

Who said it's CLOSED? That's the OP's job, not someone who just happened along and had nothing to do with the thread...

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

Agree with narue's code !
Another modification that can be used, that is dman01's idea using getch()

Advantage : It tells the user at that instance whether he has given an incorrect input rather than after entering the whole string

Disadvantage : Not a very reusable code, may not work on all versions of c++

Disadvantage : this is why we do NOT make this suggestion... It works on very few versions of C++.

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

Yes.

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

So what's the problem on that line? We can't read your mind.

I see no problem at all. If that line is executed once, Grade1 contain -28. If that's what you see, that's what you should expect.

Just to point out, when the you define your 'grades', the initial values are:
Grade1 = -29
Grade2 = -9
Grade3 = -29
Grade4 = -30
This info may be of interest.

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

Can anyone explain me how to find a point on circumference. The data i have is radius and the coordinates of circle center. I tried to get it by using (x-a)^2+(y-b)^2= r^2 formula but i get stuck. I'm not asking for solution but for explanation.

Getting "stuck" tells us nothing. Maybe stop eating peanut butter while you program.

Any request for help must contain details about the problem you are having. So clue us in...

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

What is the importance of STEAK even we r with CHICKEN today?

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

I need to basically rewrite grep command:

method is suppose to take an exact string and an exact filename as the 2 arguments
grep<string><filename>
then it has to search through the file for the string and print out the "line" and the "line number" the string is in.
example #grep matt students
12 the student matt was late for class today
35 when class started matt was just walking in the door

Im using some code from a website.

There's your first problem. You don't know C well enough to modify existing code to try using someone else's code as a starting point. Therefore, start over and take it a step at a time.

1) Input, and display the 2 values. When this runs without error...
2) Open the file name specified in the FILENAME parameter. When you get this correct (complete with error processing)...
3) Read the file line by line in a loop and display each line.
Continue until the program is running as you wish.

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

I was in the community center - community feedback and I clicked on a link which was supposed to take me to forum rules but this is what I got:


Invalid FAQ Item specified. If you followed a valid link, please notify the administrator

Clicking on Member Rules at the top of the page works fine. Be more specific about what "a link" means.

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

What value do you get when you "take eof from the keyboard"?

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