445,778 Members | 2,015 Online
Need help? Post your question and get tips & solutions from a community of 445,778 IT Pros & Developers. It's quick & easy.

# Execution

 P: n/a for the following code: strncpy(temp_issue, &temp1[13], 4); files.rec1.issue_rec[4] = atol(temp_issue); cout<
13 Replies

 P: n/a "muser" wrote... for the following code: strncpy(temp_issue, &temp1[13], 4); files.rec1.issue_rec[4] = atol(temp_issue); cout<

 P: n/a On 29 Jul 2003 13:07:51 -0700, ch**********@hotmail.com (muser) wrote: Have I gone out of bounds at all. How can we possibly answer this question? John Dibling Witty banter omitted for your protection Jul 19 '05 #3

 P: n/a muser wrote: Have I gone out of bounds at all. Anyone who thinks they can solve this mystery please respond. Real solutions please, as Bull**** doesn't get me anywhere. Ask real questions please, as Bull**** doesn't get you anywhere. Jul 19 '05 #4

 P: n/a "muser" wrote... [...] For the first 4 entries i must make sure that they are numerical digits. [...] "numerical digits" sitting one after another in a stream are a number. If the stream contains '1' then '2' then '3', it simply contains "123", which is a _single_ number. You may read it into a _single_ variable, declared as 'int number;' and you don't need to read it into an array. Do you understand that? You may also read those "numerical digits" into an array. But it has to be an array of 'char', not an array of 'int'. Do you understand that? Once those "digits" have been read into an array of 'char', you can verify that all of them are decimal digits by using 'isdigit' function (on each of them). I can imagine that the ability to read "123" into either a single value or into an array confuses the hell out of you. Try to see the difference. The value is 'int', the array if of 'char'. There is NO NEED to read them into an array of _int_. Besides, it's not easy to read them into an array of int. Victor Jul 19 '05 #6

 P: n/a > struct file1 { char record_type; char customer_name[21]; long customer_code[5]; Here are you sure, that one customer has 5 codes, each one beeing a number No! A customer has only one code. At the file level this code consists of 5 digits (=5 characters), but once those 5 digits (5 charcaters have been) read and verified, those 5 digits form a *single* number: long customer_code; muser, you really need to grasp this concept before you can go any further, Karl is right, Victor is right, I am right. You can think of a number as a sequence of digits, that's a char array, or you can think of a number as a mathemetical entity, that's a single long, not an array. You use the char array to read in the number and to check that it is all digits, but then you convert that to a single long. Make the changes Karl, Victor and I have suggested. john Jul 19 '05 #9

 P: n/a Karl Heinz Buchegger wrote: long customer_code[5]; Here are you sure, that one customer has 5 codes, each one beeing a number No! A customer has only one code. At the file level this code consists of 5 digits (=5 characters), but once those 5 digits (5 charcaters have been) read and verified, those 5 digits form a *single* number: long customer_code; However, I don't think a long is appropriate for storing things like customer codes or phone numbers or other things that have numeric components but aren't used in numeric processing. I believe that was what Victor was getting at. Such entities are really strings, even though all the characters are numerals. I'd make customer_code a std::string (at the same time replacing the char arrays for name and such). This gives the program greater flexibility to represent codes. Thinking of a real-world example, suppose the company decides to add an alpha character to the customer code to indicate which region the customer lives in? Then a long is useless. Brian Rodenborn Jul 19 '05 #10