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

Well, for the line
34012 Philip Morris Lisbon Milan 01
you read:

if ( fscanf(file, "%5s %50s%10s%10s%3s",
    p[i].id_num,    // 34012 
    p[i].Name,      // Philip 
    p[i].Departure, //Morris 
    p[i].Arrival,   // Lisbon 
    p[i].Day) == 5 )

Now, what changes seem obvious?

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

thank you
that took care of the first error
but i am still having an issue with using the function

My psychic powers aren't awake yet...

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

You cannot define a function within main() . Move it above.

And thank you for using CODE tags and formatted code on your first post! What a rare thing around here!

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

>Let the random function print 50 numbers and I'll decipher a pattern out of it.
Okay, then please do so:

If these numbers end here,I'd say something like:
let user start with x.
the series is x,x+12,x+15,x-4,... I think you get it.

You're kidding, right? Yeah, we get it, Smokey :icon_rolleyes:

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

Please reread the Forum Rules and pay closer attention to this section.

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

and the fastest modem available was 300 baud.

or the teletype hardwired to the computer that takes up an entire room runs at a blazing 110 baud!

I still have 3 paper tapes
ascii art (if you squint a bit) ladies scantily attired
just need somebody with an ibm 360 or 370 to load them on

Remember Lenna?

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

Can you hide the CANCEL button? If so, process Cancel code using the OK button.

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

Thank you for using CODE tags, but you need to FORMAT your code so we can follow it. CODE tags only work with FORMATTED code.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
cout << square << endl;

That's because you printed the value of square . You didn't actually call the function.

Look up calling a function in your text.

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

Another suggestion: format your code better. Indents are too deep and not consistent.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Salem commented: YES YES YES! +18
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Did you bother to read:
http://www.daniweb.com/forums/post1095425.html#post1095425

The OP took my code-only response and elaborated on the reasoning for the logic. Not only did he understand it, he posted back a "more detailed description" PLUS another way of going about it....

Count the number of times someone was spoonfed an answer. Then count the number of times they have elaborated as your "student" did. The ratio is extremely small and not worth the chance of a cut&paste.

Who cares?

I do, for one. Especially when I've attempted to help them understand the process and some newbie coder with a 'look what I can do' ego hands them a complete program on the next post. He not only teaches the OP that this is where you get your homework done free, the time we spend giving a helpful answer has just been wasted.

I disagree. Sometimes I answer questions with pure code, as the code speaks for itself:
http://www.daniweb.com/forums/post1098395.html#post1098395
http://www.daniweb.com/forums/post1095425.html#post1095425

So with that reasoning, again, I should be infracted.

Will that code work dropped right into the OP's code? Then yes. If the code doesn't answer the question directly but solves a similar problem, and the OP can use it to solve his problem, then no.

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

IMAO spoonfeeding should be an offense. But the Rules as written allow it. This has been discussed before and while spoonfeeding was not encouraged, what could we really do about it? Infracting is too harsh but that's the only 'punishment' we have.

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

Please mark as solved.

Why? The title "Thoughts on Google Chrome..? " is an invite for discussion. One person saying "try this instead" is IMO not a discussion... :icon_wink:

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

Two things:
1) Learn to format your code so we can read it easily
2) Where in the universe does "it gives an error" follow from "it runs without problem"? White is not black...

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

As for your problem, where does the player start from ? I don't see
a way to get in the maze from outside, so I figure there is a starting point.

I think there must be a start position too!

Ummm, guys, read the post:

The program is run with command line arguments, e.g. maze.exe maze.txt 1 1
where maze.exe is the compiled program, [doh!!!]
maze.txt is where the maze is saved(same directory as maze.exe)
1 and 1 are the start coordinates(must be a p)

tux4life commented: Exactly. +6
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

IMO, better code would be:

#include <stdio.h>
void foo(void)
{
   int i = 1;
   while ( i )   // or while ( i != 0)
   {
      printf("\n1: Stack1\n2: Stack2\n0: to return\n");
      scanf("%d",&i);
      switch ( i )
      {
      case 1:
         printf("1");
         break;

      case 2:
         printf(" 2");
         break;
      case 0:
         printf("Thank you for using the service");
         break;
      default:
         printf("Give a Valid Option");
         break;
      }
   }
   return;
}

This leaves one exit of the function -- at the end. I feel it's cleaner, but that's just me...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
#include<stdio.h>
int main()
{
 char sh[100] = "ED",*stop;
 int test;
  
 test = strtol(sh,&stop,16);
  printf("Test:%d",test);
}

Very nice. I assume it works now...

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

My question is the following, i'm just figuring out this language, now my question is about the "n" number.

What is the role of n<5, i know after this condition it continues the for or not.
But i can't find the precise explanation of the "n" . Thank you.

n is called a loop counter. You start n at 0: for ( n=0 ; n<5 ; n++ )
At the end of the loop, you add 1 to n : for ( n=0 ; n<5 ; n++ )
Then the loop continues if n is still less than 5: for ( n=0 ; n<5 ; n++ )

Why are n<5 and n<6 outputting the same result? And why n<4 is so small?

Luck. Since billy is defined as 5 integer array, when you access billy[5] you are beyond the defined array and accessed memory you shouldn't. It just happens to work and the garbage value is used. Another result could be the program crashes since the memory is undefined. That's why you're lucky.

As for why n<4 is small and n<5 is big, use pencil and paper and execute the program at your desk (called desk-checking the program). The reason will become obvious.

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

If you are having a problem with

Add a feature to You code that it will take notice of the rerurn value of scanf() and use this return value to get rid of that previouse error You did discover (about characters)

then you did not understand what happened when you followed these instructions:

Test Your code by giving a character when asking for numbers. What did happen and why ?

Examine the functionality of scanf() - function ( read the man pages). Examine what are the scanf-functions return values also in error condition.

Give the answers to C-file as a comment.

What did you discover doing these steps? What did happen? Did you figure out why?

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

Accept input as a single character
Test the character to see if it '0' thru '9'
If it isn't, tell user it's not an integer.

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

How do I do that?

Let me count the ways:
1) in the Rules you were asked to read when you registered
2) in the text at the top of this forum
3) in the announcement at the top of this forum titled Please use BB Code and Inlinecode tags
4) in the sticky post above titled Read Me: Read This Before Posting
5) any place CODE tags were used, even in responses to your posts
6) Even on the background of the box you actually typed your message in!

Does this help?

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

Try Google.

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

We aren't psychic. You need to show us what you tried so we can help you fix it. Did you read the forum rules? Did you read any of the sticky posts at the top of the forum?

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

When you test each character do you really want to use i to save the result?

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

Run this program:

#include <stdio.h>
#include <string.h>
#define NEXTCOL 38

char *strs      = "ABCDEF";
char *strl      = "ABCDEFGHIJKL";
int   sizesingle= 9;
int   size[][2]= {   3,  3,   -3,  3,    3,  9,   -3,  9,
                     3, -3,    3, -9,   -3, -3,   -3, -9,
                     3, 15,    3,-15,   -3, 15,   -3,-15,
                     0,  0,
                     9,  3,   -9,  3,   -9,  9,   -9, -3,
                    -9, -9,   -9, 15,   -9, -15,   9,  9,
                     9, -9,    9, -3,    9,  15,   9,-15,
                     0,  0,
                    15,  3,   15,  9,   15, -3,   15, -9,
                    15, 15,   15,-15,  -15,  3,  -15,  9,
                   -15, -9,  -15, 15,  -15,-15,  -15, -3,
                    -1,  0
                  };
char buf[20];
                
int main()
{
    int  i = 0;
    int  j;
    
    j = printf("  Short -- %d chars <%s> ", strlen(strs), strs);
    while (j++ < NEXTCOL)  putchar(' ');
    printf("  Long -- %d chars <%s>  \n", strlen(strl), strl);
    printf("\n");
    
    j = sprintf(buf,"%*s", sizesingle, strs);
    j = printf("       %%%3ds (%2d)  <%s> ", sizesingle, j, buf);
    while (j++ < NEXTCOL)  putchar(' ');
    j = sprintf(buf,"%*s", sizesingle, strl);
    j = printf("       %%%3ds (%2d)  <%s> ", sizesingle, j, buf);
    printf("\n");
    
    j = sprintf(buf,"%*s", -sizesingle, strs);
    j = printf("       %%%3ds (%2d)  <%s> ", -sizesingle, j, buf);
    while (j++ < NEXTCOL)  putchar(' ');
    j = sprintf(buf,"%*s", -sizesingle, strl);
    j = printf("       %%%3ds (%2d)  <%s> ", -sizesingle, j, buf);
    printf("\n");
    
    j = sprintf(buf,"%.*s", sizesingle, strs);
    j = printf("       %%.%2ds (%2d)  <%s> ", sizesingle, j, buf);
    while (j++ < NEXTCOL)  putchar(' ');
    j = sprintf(buf,"%.*s", sizesingle, strl);
    j = printf("       %%.%2ds (%2d)  <%s> ", sizesingle, j, buf);
    printf("\n");
    
    j = …
Gaiety commented: Fantastic Answer +1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Do you know how to write to a file? That's pretty much all you need to know.

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

can any 1 help me with that !! plz

Yes, of course.

As you know by reading the forum rules and the sticky posts at the top of the forum you forgot to post a few things with your request.

Keep in mind every letter has a distinct numeric value (A=65, a=97, etc). Use that info and an array and you should be able to do this program easily.

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

Being a human and not a computer, it helps to give details. What is input? What should be output? What is actually output?

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

To compare a character value, use the character. Single quotes around a single character is what you need: if (chr == 'y') And remember, 'Y' and 'y' are not the same values...

For comparison, double quotes go around a string (or multiple characters): "This is a string"

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

what is data type specifier

Google? Your book?

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

In gcd() you return v, but that's the value you passed into the function unchanged.

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

If there aren't any questions relating to the subject, it would be useless to add a forum. But if there are a lot of questions on the subject in an appropriate/related forum, then it makes sense.

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

when I deal with clipboard, I have to use GlobalAlloc.

That makes sense. new allocates within the realm of the program. Once the program exits, the memory is released. The clipboard then cleared (or broken). GlobalAlloc , I assume, leaves the allocated memory until the system clears it.

is it recommended to use GobalAlloc where new can be used without problem (in Windows programming)?

No.

CppBuilder2006 commented: convincing +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

> Convert the 20 into decimal, then use math to convert to hex characters. How does 20 become 0x01 0x04?
20 decimal is 0x14 in hex.

I understood. It was a Q to the OP -- wondering if he understood.

Salem commented: okies :) +18
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I am trying to take an integer argument (1-65536) and turn it into two hex characters.

First problem -- 65536 cannot fit in 2 hex characters. 0-255 can, but 65535 takes 4.

If argument -t is -t20 then I need 0x01 0x04 in a character array for sending through a socket.

Convert the 20 into decimal, then use math to convert to hex characters. How does 20 become 0x01 0x04?

Relavent snippets:

There is no relevance to this code snippet since there is no attempt to do the conversion yet. Computers don't work by magic and we -- like magicians -- don't give away secrets. We will help guide you to the secrets, but we don't give them away. Try it first yourself. Search these forums.

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

i couldnt understand how fseek(fp,-size,SEEK_CUR) helps to allocate the modified data
at the location where name are found to be same. it would be great help how fseek points to the location where
data is going to modified.

fseek() doesn't allocate anything. It places the file pointer at the specified location in the file. Reading will then return the data at that precise position.

As for writing, it's very dangerous.

-size if fseek logic of pointing to the location where to modify data

Not a clue what you are asking.

Here's your code -- commented

while(fread(&e,size,1,fp)==1) // read SIZE bytes from the file into e
{
    if(strcmp(e.name,empname)==0) // if the name is the same
    {
        printf("enter name age and salery\n"); // read new data from user
        scanf("%s%d%d",e.name,&e.age,&e.bs);
                                                  
        fseek(fp,-size,SEEK_CUR); // back up in the file to the beginning of the record just read
        fwrite(&e,size,1,fp); // write the new record over the old
        break;
   }
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

If you look inside limits.h you will see the maximum values allowed -- and the name of the variable representing the number

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

Since no answer in 3 years to original question, probably no answer today... Check with business people in your country.

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

size_t is a data type, not a data size. int is a data type. char is a data type. So is size_t. What goes into it is the result of executing the sizeof() 'function' -- it returns a data type of size_t.

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

Well, the user could manually terminate it with a nul-character, not?

Only if you want to be obtuse and argumentative. But the definition of string in no way includes 'null terminated' -- in C++ (added to stop the 'well in C' argument :icon_twisted:)

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

OK. then you need the hex value 0x1A, decimal value 26, but not 'Ctrl+Z'

DarkC0de commented: thanks +1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

... the underlying representation of std::string is not necessarily "null terminated"...

Actually, a string is not "null terminated". Period.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Salem commented: Heh, and it wasn't rm *.c - lol +18
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You are attempting to round based on the .5, not the .57. Each answer should be 11.

Did you try desk-checking the code? Assume input = 10.57. You write down the result for each step and keep track of all the variables: b= b*10; -- what's the value of b? d= (int)b%10; -- what's the value of b and d?
etc.

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

Use an if statement and an ASCII Chart to test a character entered.

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

For first participation, you obviously ignored the request to read the forum rules, and completely ignored all the sticky posts at the top of the forum.

We can't help you with the information you gave.

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

I search modul for to studying c++ code ???
plase...help me...

You should read the Forum Rules to learn how to post a useful question.

"Plase"...do it...

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

Just make everything public then you don't need to!

Please reread Narue's response -- carefully -- and you will see why this is a bad suggestion.