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

In your main() , look carefully at your if statement...

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

Never claim your question is urgent. Many people here will completely ignore any post that has that word in it. No question is ever urgent posted here. We'll answer it when we get to it. You're just lucky this time...

As for your problem, see this
Don't blindly output your '-' after your loop. Count the characters as you read them. When you read the 5th character, output your '-' and reset the count.

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

Ahhh, that's how it works! Thanks SOS

~s.o.s~ commented: you're welcome :-) +27
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You opened filein and you're reading from cin.

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

What link? "Latest Reputation Received" is not a link for me.

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

you mean the index = 0;
i seriously don't know what that means. i have seen it before but i don't know what it does
and which loop do i use? For loop?
and how do i add the contents of my array

If you don't know what index = 0; you seriously need to start reading your book before continuing. I suggest you talk to your instructor...

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

Your first attempt was much better. Writing functions is the way to go, as you were doing. Don't follow nucleon's advice.

Do not use scanf() to read strings. Here's why.
Don't use feof() either. Here's why.

Tell us the following:
1) What is a stack?
2) How can a stack be used to test for palindromeness.

If you can answer these two questions, how did your program implement the stack?

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

Boy, you guys just don't understand. Birds don't live in the sky. They land to sleep, they land to have their birdlets, they live most of their life not flying!

As for the video -- what the heck was that about?!?!? :confused:

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

Or little green monsters from Mars ???

Just play Slim Whitman songs....

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

Don't be so square!:icon_mrgreen:

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

In this daniweb site, is there a way to search for a particular item. Example: I want to see what a solution may be for ssolving temperature? If so, how do I search all the threads for that. Just curious!

Umm, try typing in the particular item in the search box -- maybe?

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

Because we already got our grades and passed the course. You can't pass using our work. You need to pass on your own work.

Salem commented: Well said +29
tux4life commented: Well said :) +1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

We can just get the code from Bable Fish and modify it to properly format the translations to be syntactically correct for the new language. Should be trivial... :icon_twisted:

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

Same. I always just type quote and quote

I just hit Reply w/Quote and let the system add the quote tags with the quotee -- without the spacing or periods.... :icon_wink:

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

Keep in mind that when you have a 'string' as an answer -- for example 5' 2 3/4" -- each of these answers will be wrong:

5', 2 & 3/4"
5'  2 3/4"
 5' 2 3/4"
 5 ft, 2 3/4 in

IOW, a string input may not be a good option. Multi-choice might be the best solution.

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

And to prove that he's an..., try this:

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    char line[80];
    ifstream inFile("x.x");
    
    while (!inFile.eof())
    {
        inFile >> line;
        cout << line << ' ';
    }
    inFile.close();
    return 0;
}

Use this file:

ONE
two
Three

What just got output?

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

What you are attempting to do can be done with arrays.

Imagine you have an integer variable called "number" with a number, and when you executes a function, this function creates a variable called "audio1" and increments number (number ++; ). The next time this function will create another variable called "audio2".

With audio as an array, you can reference audio[1], audio[2], etc.

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

Well, the moderators who are supposed to strip those posts out would need to keep saging off.....

Moderators are not supposed to strip posts out

posting new questions in old threads isn't supposed to happen (or receive any kind of answer other than "how 'bout you post a new thread") anyway.

But it does happen. Cats aren't supposed to climb on the dining table either. But they do.

As comatose mentions, new members posting a question on an old thread isn't expected to get an answer anyways,

Oh? They posted a question. They want an answer. How are they supposed to know they should not expect an answer to their question?

he is supposed to be smart enough to check the dates and start a new thread.

Let's stop supposing, shall we? Deal with reality, please...

Also from the conversation on this thread (which I witnessed two days back too), old threads do host an announcement saying that "This thread is more than three months old - Perhaps start a new one."

And the background of the coding forums say Use Code Tags. 80% of new posters don't. Why would one think an 'announcement' would help this situation?

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

I repeat. Output a character at a time. In addition, stop when you reach 10.

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

So?

Salem commented: do ray me fa +29
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Just use an index into the array and output one character with putchar() at the correct screen location.

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

Hello..... i got a problem where my output are repeated.....
how to solve this problem....

Er nevermind, couldn't see that last bracket.

Good. I'm glad you got it because you didn't tell us what the problem was which makes it hard to help you to solve it.

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

Start by defining two arrays, first to hold the values and second to hold the vowels themselves. Then use loops to check the input characters with the letter array and increment the correct value in the other array (or define a 2D array to make it easier).

Then for the sort be sure you sort both arrays at the same time. Don't use the sort() function, but sort the values by writing your own code.

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

Tag a system("pause"); before return 0; and see what happens.

You might want to read this.

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

Resurrecting a 5 year old thread to ask us to give you a free grade is frowned upon.

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

If menu() returns a value, then return the value. It should be a char , not void , function.

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

BTW, char chr_digits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '\0'}; is same as char chr_digits[] ="0123456789";

True. But based on the code you don't seem to need a string, just an array of characters. So char chr_digits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; is the 'correct' definition.

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

@csurfer
i thought that you cannot read a string like scanf ("%s", stu_name[j]); if you defined stu_name like char stu_name[MAX_LENGTH];

Yes you can, but you shouldn't. If your string has a SPACE in it, you only read up to that space. And reading a string with scanf() is identical to using gets() , so should be avoided at all costs. Use fgets() .

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

What way(s) can I reread the same file in C? I've only been able to find C++ tutorials. I tried:

fclose(infile);
infile = fopen(argv[1], "r");
//error checking

but this code didn't go to the beginning of the file.

Any time you open a file you are automatically at the beginning of the file. So I don't understand what the problem is.

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

I'm not sure how adding if statements for edge checking makes the code simpler. In my experience, additional code always complicates, rarely simplifies, readability.

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

why and?? because is like the user only need to put a or b not a and b

Because with OR the comparison is always true. The only way the IF can be false is if input[position] is equal to all of the letters, an impossibility.

The other reason is -- you code isn't working, is it?

i got to this part but is still didn't work...plz help

With what? You didn't explain what is wrong.

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

IMAO, giving bad rep then giving good rep to nullify it is asinine. If you think they deserve bad rep, give it. If you're concerned about their rep points going in the toilet, don't give it.

The only thing I've seen in this thread that makes even a little sense is being able to give neutral rep. Basically turning it into a simple comment.

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

Hi,

I'm trying to pass parameters to an exe file using C++...i tried the following code:

system("FileName.exe");

but this command line just fire the .exe file without passing any arguments...

Thanks,

Mostafa Fouly

In order to pass arguments you have to pass arguments. All you did was execute the program.

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

It's your antiquarian ...

antiquarian -- The compiler is not a person. Antiquated is the proper term.

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

The idea behind c-strings is that they end with a '\0' character. You have defined the array to be 11 characters then ask for 11 characters. There is no room for the \0. You must only read 10 characters.

And on a style note, if you ask for the string in main() , you should read the string there. The function should only convert the string.

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

First, please learn to Format your code so we can read it easier.

You need to store each factor in an array as you generate them. Using your 100, you first generate 2. Save it in the array and you have 50 left. Run the loop again on the 50 and you'll get 2 again. Store it with the other 2. You have 25 left. Again and you'll get the 5. Store it. You loop on the 5 and discover it can't be reduced. Store it with the rest then output the array.

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

You're reading into an integer and each line contains an integer. Even though you didn't explain what you actually want I assume you mean to read each individual digit into the j_mapKey array. If so, read each digit as a char and convert to an integer by subtracting 48.

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

Also, note how the two biggest portion of our debt is due to Liberal politics: Medicare and Social Security. Wow, what an intelligent idea!

Not even close to the truth - where the hell do you get your data. I want links; come on - support your statements!

1945            [B]Harry Truman[/B] sends a message to Congress [B]asking for[/B]
                legislation establishing a national health insurance 
                plan.  Two decades of debate ensue, with opponents
                warning of the dangers of [B]"socialized medicine."[/B]
...
July 30, 1965   [B]Medicare and its companion program Medicaid[/B],
                (which insures indigent recipients), [B]are signed into 
                law by President Lyndon Johnson[/B] as part of his 
                "Great Society."

                Ex-president Truman is the first to enroll in Medicare.

http://seniorjournal.com/NEWS/2000%20Files/Aug%2000/FTR-08-04-00MedCarHistry.htm
AFAIK, Truman and Johnson were not conservatives. Aren't Democrats known as liberals?

Franklin Delano Roosevelt (January 30, 1882 – April 12, 1945), often referred to by his initials FDR, was the 32nd President of the United States. He was a central figure of the 20th century during a time of worldwide economic crisis and world war. Elected to four terms in office, he served from 1933 to 1945 and is the only U.S. president to have served more than two terms.

During the Great Depression of the 1930s, Roosevelt created the New Deal to provide relief for the unemployed, recovery of the economy, and reform of the economic and banking systems, through various agencies, such as the Works Project Administration (WPA), National Recovery Administration (NRA), and the Agricultural Adjustment Administration (AAA).[1] …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You really need to tell us the real problem, which is "I cannot get the program to compile. The error message I get is..."

You cannot define a function within another function as you are doing. round() cannot be within main().

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

There is no built in way. Easier? Can't think of anything easier than checking characters.

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

So I think I need to take this step by step... Start out with getting the line with the search term on it, and priting out that line. Any ideas on that?

Once I get the line printed out succesfully, we can figure out how to get the words I need out of the line.

This is an excellent idea. You give it a try and we'll help when you get stuck. But you have to get stuck first. Look up the methods that can be used to compare strings and get substrings.

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

Since you never initialized command_array , it starts out with junk in it. Then you added your input to that junk.

Is the first parameter to execvp supposed to be a single character? That's what you are passing.

After making changes you should repost the code so we can see it's current state.

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

Well, I want to know how to insert a full string into the array of strings. I thought it might be:

fscanf(infile, "%s", *arr[i]);

but this line gave me the error "warning: format argument is not a pointer (arg 3)".

No. It would be fscanf(infile, "%s", arr[i]); But, see this about scanf/fscanf. It would be better to use fgets() instead.

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

Sorry about that... noobie :)

Not an excuse. There are at least 6 places where CODE tags are suggested/described. The first is in the rules you were asked to read when you signed up. The last is right on the background of the input box you typed your message into.

#include <conio.h>
...
   while( _getch() != 13 ); // or try  getch()

This only works with Windows...

Completely non-standard and not recommended. You should recommend something anyone can use, like cin.get() or some other C++ input function that is part of the language. And 13 is '\n', which should also be used.

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

Hope you can get the above code.(Its quite cumbersome) This will definitely do your work.

Hope you get a good grade for the program, csurfer.
claretm certainly doesn't deserve it.

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

I hope you get a good grade on the assignment, Comatose

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

The problem with AD's solution is you never really know when you're at the beginning of a line.

You can:
Read a complete line.
Test the beginning for the word in question.
If found, there are many ways to 'parse' the line.
1) looking at each character and dealing with SPACEs and non-SPACEs as appropriate.
2) Use stringstreams to parse the line
3) use the strxxx functions.

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

Start by writing a program to determine the prime numbers less than 1,000,000. Then modify the program to test the differences.

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

Actually, you can't assign a char to a string, but you can add a char to a string. A minor change to you program above:

int main()
{
  string user_input;
  string first = "";
  
  getline(cin,user_input);
  first += user_input[0];
  cout << "Frist character is  " << first << endl;

    return 0;
}

seems to work.

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

If the instructor hasn't explained the difference we can do, and that's why i pointed it out. It was more of a piece of info than anything else.

really?? Why don't you take his code, run it as it is and check the output?

Sure. Just the minor change correcting his loop I get

d:\wjp>x
Input a string: this is a test

There are 4 words.
d:\wjp>x
Input a string: this   is   a    test

There are 4 words.
d:\wjp>

Is this OK? :icon_rolleyes:

Please tell be what I did wrong...

#include <stdio.h>
#include <ctype.h>

void input(char *str);
int Ecount(char *str);
void Display(char *str);
void Wcount(char *str);

void main(void)
{
	char S[50];
	int count;

	printf("Input a string: ");
	fgets(S, 50, stdin);
   Wcount(S);
}


void Wcount(char *str)
{
	int i=0, word_count=0;
	while (str[i] !='\0')
	{
		if( isspace(str[i]) && !isspace(str[i+1]))

			word_count++;

		i++;
	}
		printf("\nThere are %d words.", word_count);

}