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

extern the variables in question. Look it up...

valestrom commented: Made me look, but still very helpful +1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Forget the vector. Just
1) Create a string array with all the names in it.
2) Use srand() once to initialize the random function.
3) call rand() to get your random number x from 0 to 3
4) Display the xth name from the array.

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

I need a simple error check, so that if the user enters the wrong type of character, he/she will be notified and allowed to re-enter a new value.

Rad the input as a string. Then test each character to make sure it's a valid number.

Secondly, I need some sort of loop that allows the user, after having running the program at least once successfully, to choose whether or not to run it again.

Use a do-while loop. Start it just before the first statement you want to start repeating. At the end, ask your yes/no question. Use a condition that stays in the loop if YES is indicated.

That's a start...

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

Do you know what the term append means? fp=fopen("c:\\folder/file.txt","a+");

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

sizeof() returns a binary value. Decimal and Hexadecimal are simply display values of those binary values to the user. If you see hex values it's because your cout has been told to display the value as hex.

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

As I said

The Algorithm:
Given the first two terms are 0 then 1, each successive term is the sum of the previous two terms.

That fits the definition and has none of the stuff the instructor claims doesn't belong. And you can use it to program the series.

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

C++ will not and should not die because I just started learning it...

That's the most compelling reason why C++ cannot die. Jingda just started using it!

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

The Algorithm:
Given the first two terms are 0 then 1, each successive term is the sum of the previous two terms.

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

hummmmmmm....

Have you see to teh end of my post:

Maybe I stopped reading after the horrible misspelling of typical... :icon_wink:

is this the best and fast method?

Are you making a challenge? Best and Fast are rarely if ever the same method.

I guess you had better explain why my suggestion is no good. Do you have a better solution?

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

I have one problem, i have to put some special cases in there like it cannot allow
(1+2+A) and (1+2 5+4) if these happen then i write invalid sequence to the output file. Help please.

Look at each character one at a time. What are the acceptable characters that can follow the current character?
For example:
Currently a digit. Next can be digit, SPACE, operator. So set some booleans to TRUE.
Next character...
Now a SPACE. Next can be SPACE or operator only. Set two bools to TRUE, one to FALSE.

Something like that...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Sub btnModify_Click()
    delete *.*
End Sub
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
while left(line, 8) <> "INIT0000"
   READ NEXT LINE
wend
do
   PROCESS LINE
   READ NEXT LINE
while left(line, 8) <> "INIT0001"
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

try to avoid the header file conio.h.

Do. Or do not. There is no try... :icon_mrgreen:

Appropriate statement is "Avoid the header file conio.h."

Everything else asitmahato said is correct. But remember, in English there is a SPACE after every period. Period. Note the SPACE. End transmission. -30-

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

strcmp()

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

No.
You have to read the file and search in the buffer you read.

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

Use PKZIP, WinZIP, WINRAR, 7ZIP, or any other file archiving software.

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

Please format your code at all time so we can read it. This has been mentioned before.

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

I think you want this....

Why would you add conio.h and getch() , yet not remove system("pause"); -- both being unacceptable?
How about correcting it properly with cin.get() or cin.getline() ?

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

What does your "garbage value" look like?

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

Reread what Adak posted.

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

My wwell paid (recently graduated) job is writing C++ applications for embedded linux devices. My web-developmnent friend is currently unemployed.....

If you were in India or Pakistan, your statement would be relevant. As it is, your statement is irrelevant... :icon_wink:

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

You simply parse each string (argv[1], argv[2], ...) one at a time.

Decide on a parameter format and parse based on your decision. For example, my style is prog -iInputfile -oOutput -tTimeValue -nNumeric So if any string doesn't start with a -, the parameters are improperly formed
Then test the 2nd character and parse the rest of the string according to the format specified (i & o=file format, t=hh:mm format, etc.)

The format you specified is
1) start with 2 dashes --
2) next is a keyword
3) then a single =
4) finally a value in the proper format for keyword

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

Not a clue what you are talking about.

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

He has the choice to go to a real university where they teach you relevant technology........

In that case, he'd be studying HTML and either Python or Ruby right now, and we wouldn't be having this conversation (or at least not for another few semesters). While I have used C++ professionally myself, I'd expect that for the current classes of graduates, C++ jobs are the exception rather than the rule.

Really? You mean universities no longer teach C++ as a relevant technology? HTML is their relevant technology?

So sad... In that case, go into sports instead of computers. Hopefully they teach students how to run and catch properly.

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

Here's a book for you to have your concepts clear: http://bit.ly/qmRTsK

I would recommend a better book.
1) He's from India -- the home of teaching with 20 year old tools
2) He recommends Turbo, Borland, both very old compilers.
3) The code in the chapter questions use void main() which has never been correct.

In other words, he's locked into old techniques and will teach bad habits.

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

First, look at the actual CSV file and get a feel for the pattern of commas and quotes. Then figure out how you'd separate the data. Now how do you translate that into code?

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

And to the KeyUP() event, stop playing the note.

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

WoW, it isn`t like we learn in school.. :O
But, tnx for reply...
^____^

That's because your school teaches 20-year-old techniques on 20-year-old software. They don't bother teaching today's C/C++.

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

These IF statements, at the moment, are wrong because I am comparing str1 with G1 which will always be TRUE. I need to compare the incoming data with str1 (G1) which I am unable to do so far. The incoming data will be compared to str1 which is G1 and if the incoming data is a command executing G1, then the dispenser will be ON. I hope I am making some sense. This is what I am after.

P.S: G1 and G28 are g codes like in a CNC machine.

I can't tell if
1) you know what you want to do but just haven't done it yet. It's a later modification.
2) you have no idea how to do what you want to do.

It would help if you explain clearly what you need help with in detail.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
void loop()
{
 char str1[] = "G1";
 char str2[] = "G28"; 
  
  if (strcmp(str1, "G1") == 0){
  
    
      //turn dispenser on
      digitalWrite(2, HIGH); }
    
    if (strcmp(str2, "G28") == 0) {
    
      //turn dispenser off
      digitalWrite(2, LOW);}  
}

Could you explain to us when will these IF statements be false?

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

In filer::makefile() , why are you setting a boolean value truly_random to NULL? It's boolean. Values are true and false.

You also test it for 1. Again, true and false.

And based on your code, you will never call srand() since truly_random will never be 1

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

I have made a following program that will convert lower case letters in to upper case and upper case letters will remain same and that will be done Realtime (as character is typed).

#include<stdio.h>
#include<conio.h>
void main(void)
{
char ch;
printf("Type a sentence: ");
while (ch!='\r')
{
ch=getch();
if (ch >=97 && ch <= 122) // if lowercase
ch = ch -32; // change to lowercase
printf("%c",ch);
}
getch();
}

But now I want to add an option that, user enters a character number to capitalize.

Following should be output of the program:

Enter sentence: hello how are you?
Enter char number to capitalize: 2
Output: hEllo hOw aRe yOu?

Any help? I don't know how to get the position of character in a string.
P.S. I don't want to use any other library function or string.

1) Use CODE Tags
2) void main() -- see this
3) Format your code
4) Why not use the simple putchar() made to output a single character rather than the complex printf() ?
5) When you start reading or you input a space, zero a counter
6) For each character input, increment the counter
7) When the counter is the specified value (2 in your example) capitalize the character entered

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

As I said:

... you need to look up the Date functions in VB. There are at least 2 that will help you.

Do you understand those statements?

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

Then read the entire document ( read() ), remove all \n's and search.

You can't find words that are split on a line without some kind of hurdle.

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

I don't do graphics. But you can search the forums. It has been answered many times.

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

Do NOT use the registry. As a new programmer you may destroy your system.

As debasisdas said, "The simplest thing to do is to check system date on start up." Which means you need to look up the Date functions in VB. There are at least 2 that will help you.

faroukmuhammad commented: I did't see that coming +4
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I see no hurdles mentioned and no reason not to use fgets() in any posts. Care to elaborate?

No one has offered this suggestion:
1) read a line with fgets() 2) use strstr() to find your word
3) check the character before the word and if it's an alpha character, it's not your word.
4) check the character after the word and if it's an alpha character, it's not your word.

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

Can anyone help? New programmer trying to write Program that prompts user to enter name of file to display on screen.
User is given to option to display another file until the user ends program. it is not working and. After compilation when 1 is chosen it scroll the question enter name of the text file name to display. when 0 is chosen the program does the same.

Lots wrong... while( reply = 1 ) -- This sets reply to 1 all the time. Did you mean == for a comparison? gets(filename); -- See This while( !feof(fp) ) -- See This

And your formatting can use some help, too.

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

That's because none of the graphics you are using is part of Dev-C++. That's the old (very old) Borland compiler.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
//using namespace std;
int main()
{
	 int i,j=0;
	 cout<<"1";
for(i=1;i<=55;i++){

if(i%2==0||i%3==0||i%5==0)
cout<<" "<<i;
j++;

}


getch();
return 0;


}

What was this code posted for? Without any description at all, my guess is how not to program in C++ since about 1/2 the code is bad and the formatting is pathetic making it hard to follow.

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

That's like asking what are the advantages of Apples over Video Games. They are two different things.

jnawrocki commented: why bother -1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Then it's better not to use fgets at all.

Why?

I think it's okay to read " char by char " than to go through all the hurdles
using fgets.

What hurdles?

What is the difference between reading character by character

while((chr=fgetc(txt_file))!=EOF )
    {
        word[i]= chr;
        i++;
        ...
    }

and reading a line at a time

fgets(buf, len, txt_file);
    idx = 0;
    while(buf[idx])
    {
        word[i]= buf[idx];
        i++;
        ...
        idx++;
    }

The fgets() code should be faster and conceptually no different.

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

Usually command line arguments are meant to pass data into the program, such as
- a file name
- switches that modify execution in some way
- specifying the exact data to be worked on

Config files 'define' the environment for the program. Such as changing the program's default values to user defined values that are set each time the program runs. For example
- folders there data can be found. Define your own folders rather than using the folders the programmer set up.
- Set default parameters to your defaults rather than the programmer's
Things like that.

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

Be wary of turning good advice into a religion. :)

Not turning anything into a religion. Just using standard good practices from a lot of years of programming.

But if you want a religion, I did walk on water once. I knew where the stones were... :icon_mrgreen:

Oh, and thanks...

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

Adding a function should be sufficient. Since you already have code that can step through a date-string and divide it into pieces, it should be easy for you to write a function that steps through and verifies that the pieces are the correct length and contain valid characters.

Yes, this is the best solution. Have it return a TRUE or FALSE to show whether the string was good or bad.

Or you could combine the two into:

  • check whether the first two characters are numeric digits
  • if so, convert to integer
  • check whether the resulting integer is between 1 and 12 inclusive
  • check whether the next character is a slash
  • ...

and if everything succeeds, copy the integers into your date-struct object.

Bad suggestion. Get in the habit of writing modular code. One function does one thing. Another function does one more thing. And so on.

Use many simple solutions to ultimately solve the complex problem.

When you start mixing your code it can become very hard to debug. Also, if your last character is bad, look at all the work you did just to throw out the string.

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

the getch() is what they have told in school.. so.. yeah.

:icon_rolleyes: Go to a better school :icon_wink:

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

Just use the header file
#include<conio.h>
It supports getch().

And what if my compiler doesn't have conio.h? Most of them do not!
Unless it's required, never use non-portable techniques to do things that can be done without tricks like this one. getchar() is the appropriate function to use.

Anuradha Mandal commented: Its a discussion center.ok.....Every one is student here......Truth or right answer comes from a discussion.If I wrong you can tell me.But dont talk like this.It breaks the rules of Daniweb..... +0
debasisdas commented: agree +13
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

So i'll just disregard the while(true) and put system("CLS") after one another?

After everything said about system("CLS") ? Get real!

Thank you Nuclear! That's it! You nailed it! :)
wow, it's really simple, but I didnt get it at the first place!

Of course he nailed it. We ALL could have, be we were trying to help you figure it out. Not give the answer, like Nuclear. Way to go, N :confused:

The problem is, his solution is not very well designed.
1) Adding 43. 0 would be better. With 43 you have to recode if you add a person.
2) A do-while when you accept the value at the top and still have to run through the loop to get to the bottom. A normal while would be more obvious.

Also, see this about using getch() . You should change to something portable and inherently C++, not a C add-on.

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

Oh I see, but it would work on Windows and Linux for his code and I doubt his O/S is set to delete his files

No, it will work on either Windows or Linux, not both. And how many O/S's are there? Can you be absolutely certain clear doesn't delete files on every one of them?