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

Hi, noob on board.

I have some issues with the spliting data according to tab.

What i need is to grab multiple inputs from a txt file and generate it into result txt file.

the input file reads like;

Johnny Bravo /tab S1234567
Systems /tab/tab DT012
VB /tab/tab DT234
Adv Database /tab DT978
.....


I can understand if all data are seperated by 1 tab, but some of the infos in the txt file, such as some subjects taking by Johnny are tabbed more than once in the txt file depend on the text length, probably because of the alignment.

Is there anyway for me to check for 1 or more tabs when getline()?

Thanks.

You know how to check for 1 TAB, right? So check the next character to see if it's a TAB too.

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

hhhhmmmm....could someone give me a jumpstart? thx

Since I did, you're welcome.

If you are having problems, you need to give us some info. After 559 posts, you should have some idea how to formulate a question that tells us what issues you have trouble with.

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

I find it interesting that, given the following requirement:

I've searched all over the place and I cannot seem to find a well working, reliable solution to this that is not platform specific.

the solutions provided are:

how bout using getch() or getche() ?
note. if u're using vc++, both are using leading underscore such as _getch() and _getche()

getch() and variants are not cross-platform.

Your best bet is to use the curses library. There are three variants: curses (the oldest and most basic), ncurses (a big improvement), and pdcurses (ditto). Most (if not all) [implication being might not work on all] Unix/Linux platforms have at least curses, if not ncurses. PDCurses, in addition to Unix variants, comes available on DOS, OS/2, Windows, Plan 9, and the Amiga. [implication: different packages for different platforms]

That covers many desktop systems people will be using (including OS X), but nowhere near all. [can't be done on all platforms]

IOW: cannot be done, which is what I said originally... :icon_rolleyes:

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

Why did you start a new thread on the same topic? Please continue with the original thread.

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

Can't be done. Change your message to Press ENTER to continue and just use the standard I/O functions.

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

lol i feel so stupid, thanks for the hints guys. we i kinda improved my code to this ...

Adding TABs to mung up the formatting is not taking a hint. Two of the three things I mentioned in my previous post was completely ignored.

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

char Data = char(); What is char()? string()? int()?
These lines I assume give you an error, therefore you have no idea if your while is messed up. in >> Data What are you expecting to read with this line? while (!in.eof()) Since .eof() is the same as feof(), read this.

That should get you started.

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

One possible way to implement this is using a magic square:

4|3|8
------
9|5|1
------
2|7|6

It was effective when I wrote TTT the first time.

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

I was just looking of ideas and clues on how to do it or understand how to go about it using a while loop, I'm just trying to learn how to write simple programs this is by no means some kind of homework. I'll take the post off if you think I'm that idle sponger.

He's not saying you are an idle sponger. He just wanted you to post code you've tried to prove you aren't.

Since you are dealing with characters, and each character is in fact just a number ('0'=48, '1'=49, ..., 'A'=65, ...) you can input your first value and, just like in math, add one to the rightmost character. Then , if the character was a number, test if it's above '9', and if it is reset it to '0' and add 1 to the next column. If a letter, test for 'Z'.


Start slow, write a small part (like the input and output), compile and test. Then add the calculation to the next plate number. Always add new functionality slowly, a step at a time and make sure it works before moving to the next step.

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

I just have trouble understanding it.

Then look up what I mentioned and ask a specific question to clear up what you don't understand.

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

If this is homework. look up strings and their methods in your text. If not, look up strings where you are getting the rest of your information. This is a trivial problem.

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

OK, let's look at this thing logically

int main()
{         

        long double num = 98;
        while ( num < 0 || num > 97 )
        {
              cout << "Which Fibonacci Number Would You Like? ";
              cin >> num;
        }       
        // you just read your FIBB number into **num**

        long double b;    // you just created **b** which contains an unknown value
        getFib(b);        // now you call your function with the unknown value
                          // what do you want to do with **num**??
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Hi, i am trying to make a program that gets words from a txt file (strings)
and see if the words have the character the user has inputed before.
-----------------------------------------------------------------------------
I have no clue what my next step is.

Maybe look at the word entered (a_word) for the letter specified (c)?

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

This is my code, and I can't figure out why its wrong.

for( k = 0; k < n; k++){
avgTemp= 0;
total += temps[n];

avgTemp = total/n;
}

1. n is the number of elements in the array, where k is 0, 1, 2, ..., n-1.

2. There is no need to calculate the average inside the loop. Move that stuff outside.

3. Don't forget to set total to zero first, otherwise you'll just have some random number.

4. If total is not a float or double, your average will be an integer, which is probably not what you want. For floating point division, make sure at least one of the operands is a floating point number.

total = 0;
avgTemp= 0;
for( k = 0; k < n; k++){
  total += temps[k];
  }
avgTemp = float( total ) /n;

Hope this helps.

How does any of the above even remotely accomplish "Reversing the elements of an array involves swapping the corresponding elements of the array..." as stated in the problem?

Do you have any idea how to swap two array values?

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

I'm completely baffled as to how to read in each room from the map file and stick each room into its own struct and have each element of the room in its own little place in the struct.

I'd really like to just use the format

fgets(rooms[i].room_num, fin);
fgets(rooms[i].room_name, fin);
fgets(rooms[i].desc, fin);
fgets(rooms[i].num_links, fin);

etc...

and get just ONE room into ONE struct.

I assume the above did not work properly for some reason. So what happened? What didn't work?

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

Yes, fscanf() is your problem. See this series to understand the complications.

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

Wouldn't it be better if your parser at least removed the color tags from syntax-highlighted code? Some people aren't aware that color tags don't work in syntax-highlighted code tags (or they paste it from their editor, which for some reason has the code all colored), and then all we see is a bunch of BBCode crap.

Nyah. If they want to screw up their code and post without a PREVIEW, let them. We just don't have to read it since they didn't care enough to verify their post.:icon_twisted:

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

I've re-worked this code enough times that my brain is about to explode. The following is an (obviously) incomplete version of how I'm starting things off. I suspect some gross conceptual error, but I can't figure it out. At this point all I want to do is get the program to get the room name and room number, and print 'em.

Figure what out? We know what you're trying to do, but you didn't tell us what's actually happening. Knowing that will help us understand he problem.

Kinda like "hey Mr. Mechanic, I want my car to start when I turn the key. Fix it.." What's likely to be his first question?

Also, knowing what's being read might be important...

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

Just on the screen

And your formatting is still not very good.

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

IMAO, the word to is inclusive of the two numbers, so it would execute 10 times. But that's just my opinion of that FOR command

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

Jeez! C'mon. Stop the mud slinging.

mandsmom, if you don't like an answer, say thanks and ignore it. Narue is one of the best programmers here, but she's also one of the most annoying if she thinks you're not listening or she believes you aren't trying. Sorry, you have to deal with it.

If you liked what I said, try it and move on.

As for the post of Narue's that pissed you off, she was right on all counts. We all have seen lame attempts at cheating. But if you didn't cheat, the statement doesn't apply to you. Ignore it. Etc.

So change your code and try it again. Post if it still doesn't work, and ignore everyone but me! :cool:

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

Okay, here's what I have so far:

#include <iostream>
#include <conio.h>

void main ()
{
clrscr();
int array [3], t;
for (int  x=0; x<3; x++)
{
	cout << "Enter integer number" << x+1 << " : " << endl;
	cin<< array[x];
}
for (x=0; x<3; x++)
{
for (int y=0; y<2; y++)
{
	if(array[y]>array[y+1])
	{
		t=array[y];
		array[y]=array[y+1];
		array[y+1]=t;
	}
}
}
cout << "The integers in ascending order are : ";
for (x=0;x<3;x++)
cout << endl << array[x];
getch();
}

There are six errors so I have a lot of work to do :icon_frown: but is that a start? Or am I completely off?

Looks pretty good so far. Here is some work you never knew you had to do:
1) #include <conio.h> -- old, non-portable header. When you get a job you probably can't use it, so stop now.
2) void main () -- main is NEVER a void. It's an int, always has been. See this.
3) clrscr() -- same as #1
4) getch(); -- same as #1
5) Formatting your code. It's not as bad as a lot around here, but check this out for more ideas.

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

>Without actually naming letter grade how will it know to save it as that?
Dude, are you really this helpless? When you print the letter grade to cout, print it to outFile too. I completely fail to see how that's not the most obvious solution in the world.

Hmmmmm...

... the shallow end of the programmer pool

:icon_question:

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

>Which unfortunately if I understand it does not allow
>you to stream the information into an array of strings
I don't see that restriction anywhere. In fact, while you're prohibited from using std::string, there doesn't seem to be a restriction on std::vector, so you can greatly simplify how you handle the array of strings by making it a vector of strings.

:icon_rolleyes:

>and they *deeply* frown upon using things we eh 'shouldn't' know yet.
Probably because they don't want you to discover that your teachers, who should be experts on what they teach, are actually only about half a chapter ahead of you in learning C++. ;)

I can think of other possibilities :icon_wink:

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

There's a page 2?

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

See response to your other post.

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

Actually, you should probably Read This!, then post back.

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

Sure. Start with your input, make sure it compiles and works.
Then add the next step as per the instructions. Compile and test.
Keep it up until the program is done.

You might want to Read This!

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

yes

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

In this code of yours (formatted for readability):

if (strcmp(num, search) == 0)
    {
        ...
    }
    [B]// is the following IF necessary?  Doesn't the ELSE automatically
    // assume this condition because of the above IF?[/B]
     else if (!strcmp(num, search) == 0)
    {
        ...
    }

You can leave off the second IF because it's true by default.

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

My compiler tells me that I cannot declare the function Primelist(float) without a type...

main() is an int type. What type did you define Primelist(float) ?

... and that the prototype for it does not match any in class 'Primelist'

Well, how is it defined and how is it used? Are all the parameters of the same type?

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

how to print /n

Start your own thread. Don't hijack someone else's discussion.

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

What's the purpose of the equation? What function is responsible for this feature? That's where it goes... Somewhere around 21 is correct.

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

First things first: Format your code

2. Remove all the duplicate letters in the key phrase.

Nested loops.... Replace any duplicates with SPACEs. When done, compress the SPACEs out.

3. Remove the letters that remain in the edited key phrase from the string of the 26 alphabet letters.

This one is easier than above, since you know there are no duplicates. I assume you know the relationship between letters and the value of the letter (A==65).

4. Connect the edited key phrase to the front of the edited alphabet.

This you can probably figure out.

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

I would guess that the 2 following lines do not equal search, since that is the only delete requirement. You need to either
1) know what the next two lines contain so you can compare them
2) just read off the next two lines when you get to a line to delete

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

Once we cot CODE tags in your post, you have some very nicely formatted code!

I don't see where your equation has been implemented. Can you figure out where it should go?

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

See this info. feof() is the same as .eof()

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

A percentage (0% to 100%) is a value from 0 to 1. So:
0% = 0.00
10% = 0.10
25% = 0.25
100% = 1.00

From that you should be able to figure out how to convert your input percent to internal value.

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

One possibility to consider is to allow BOLD and ITALIC using language-specific tags. Just a thought.

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

>is along the same line as goto and gets()
I'm not sure I like you lumping goto with gets. goto is abusable, but there's nothing wrong with it. gets is completely unsafe and impossible to fix. There's quite a difference there.

I'm using a different criteria than dangerous. All three are bad coding techniques. One is dangerous. one is haphazard, one promotes disgusting code. All to be avoided.

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

FORMATTING please.... SPACES and NEWLINES are your friend so the code can be read:

if ((time_and_date[i].start.hours <= 7 )  &&
        (time_and_date[i].end.hours   >  7)  &&
        (time_and_date[i].end.hours   <=16))
    {
        temp_rate = ((count_rate*60) + (time_and_date[i].end.minutes)) * 0.12;
        rate = (((time_and_date[i].start.minutes)) + (hour_rate*60)) * 0.15;
        rate_two = (rate + temp_rate);
    }
    if ((time_and_date[i].start.hours >  16)  &&
        (time_and_date[i].start.hours <= 23)  &&
        (time_and_date[i].end.hours   <= 23))
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Peoples i have tried to make this simple progrem in C...
that will print alphabets A to Z and their equivalent ASCII code.. like this
A 65
B 66
.
.
.
Z
here is da source code...

Please use English. It's "here is the source code. Unless your name is Stepin Fetchit,. Thanks. And use CODE tags...

int main (void)
{
	char code;
	for(code = "A";code <= "Z"; code += 1)
	printf("%c, %d", code[B],[/B] code);
	getch();         //  ^
}
Belrog commented: If you can't use basic grammar, you can't code. +1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I thought I responded to this... Darn...

... or (use fgetc() and ungetc() ) to check to see if the next character was also an alphabetic.

I don't recommend this. I dislike the idea of diddling with the input stream like that. To me, ungetc() is along the same line as goto and gets() -- they exist but you don't want to use them.

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

my question is should I give the full path name as C :\\Documents and Settings\\Administrator\\Desktop\\myfile.txt in the as fopen("C:\\Documents and Settings\\Administrator\\Desktop\\myfile.txt", "r") function or should I give only fopen ("myfile.txt" , "r") in order to open a file from desktop and display its content on screen.

Then that's what you should ask.

Use the full path...

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

Look up new and free .

Sorry. new and delete .

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

Sorry if I sounded rude; honestly, I was trying to. It's just getting late, and I'm tired. My appologies.

OK

I'm not sure where the problem is. I just started using rand() and am not sure what srand() is.

Then look it up! :icon_rolleyes: You know by now we don't want to spoon-feed people.

Maybe a more descriptive explanation of the problem I'm having:

When I run the program it's supposed to have random effects on the character's attributes (stated at the top of the first post). The problem is, every time I run the program, I get the same exact results. Nothing changes. I wanted the outcome (winner) to be by chance every time I run the program, but it's like rand() is giving me the same numbers with every compilation.

Yep.... Look it up.

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

can u help me what I am doing wrong in above program??

Yes, read the link you were given twice. It tells you how to do what you want. If not, ask a specific question.

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

Look up new and free .

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

Probably.

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

I clearly said "so far", meaning I was going to get around to it, but didn't see it as a priority for the moment.

So why point it out at all?

If you would have looked through the code, you would see that doing rand() once is not an opption since it has to be nested in a loop to be effective.

400+ lines. That's why I didn't. Just as you didn't comment. It takes time.

And reread my post. I mentioned srand() , not rand() .

It didn't help; and if you're going to be condescending in every post, I'd rather you not waste your time trying to help.

If you think I'm being condescending, sorry. I'm explaining why I (and most others) won't look at 400 line programs. Give us something to go on. Where do you think the problem is. Or as Salem always mentions, post a small program that shows the error or problem.