![]() |
|
#1
|
|||
|
|||
Type casts ?hi,
i have a few questions relating to the two programs written below, i'd be greatful if u couuld reply as soon as possible. (i have an exam in less than 12 hours !) CPP / C++ / C Code:
here's the second program: CPP / C++ / C Code:
anyone?simple ,easy to understand explenation???? thanks. Last edited by kai85 : 19-Jun-2005 at 12:00.
Reason: fo
|
|
#2
|
|||
|
|||
|
Quote:
Quote:
|
|
#3
|
|||
|
|||
|
Quote:
but i thought we were supposed to enter an integer on the command line. like 12 0r ... ??? i'm not sure because for some reason(don't ask me) the program doesn't compile Quote:
so this line of code would have to compile fine ,right? CPP / C++ / C Code:
again ,i can't be sure because the programs don't compile. thanks, kai85 BTW what does atol do? |
|
#4
|
|||
|
|||
|
Quote:
Quote:
Google works quite well for such questions. Its answer arrive more quickly. |
|
#5
|
|||
|
|||
google?ur right , i shouldve searched in google , but i ... nope no excuses.. i just didn't think of google.(this place is so good it just pops into mind when coming across problems)
thanx anyway. |
|
#6
|
|||
|
|||
|
In your second program you should change
Code:
Code:
(or so i remember) |
|
#7
|
|||
|
|||
|
Quote:
No; if you declare an array of four floats, it holds four floats. (The index values for such an array go from fnum[0] to fnum[3] --- maybe that's what you were thinking of.) Regards, Dave |
|
#8
|
|||
|
|||
|
Quote:
yes thats what u do when u declare an array of characters ,one extra for the null character . and thats what ive done in the other program where ive declared an array of chars . anyway has anyone tried compiling the 2 first programs? do they compile? i know im doing sth wronge. i just have no clue what it is!!! |
|
#9
|
|||
|
|||
|
Quote:
When you declare an array of, say, 7 chars. If you want to put a "string" in it, the maximum string length is 7, including the terminating null. Quote:
Well, we have no clue as to what you tried and what happened. Here are a few observations: Program number 1 needs to include the stdlib header if you are using Microsoft Visual C version 6 (that's where atoi() is prototyped). Of course, program number 2 needs to lose the [ B ] and [ /B ] thingies on the out.write() line. If you are using GNU g++, you will find that it is very picky about argument types in function calls. The first argument to the out.write() function should be cast as (const char *), not (unsigned char *), and the first argument to the out.read() function should be cast as (char *) not as (unsigned char *). With these tweaks, the programs compile and execute on my Windows XP box with Borland, Microsoft, and GNU compilers. As a matter of style, you should get into the habit of including C++ standard headers. <iostream> instead of <iostream.h>, for example. This also requires some consideration of namespace issues, as has been covered numerous times in threads on this forum. Even though the old style headers still work on all C++ compilers that I have seen, that won't necessarily always be the case. In a similar vein, the main() program should be defined as "int main" instead of using the legacy implicit "int" declaration. That is: CPP / C++ / C Code:
There are some other style issues, but basically, they seem to work (that is, they do not crash the system with the compilers that I used, and they do produce expected output --- if you know what to expect). Regards, Dave |
|
#10
|
|||
|
|||
|
Quote:
this is what i ment too. Ok I did what u said , the second one compiles fine. with the first program this is what I do: In command line I locate the directory I’ve saved the programs in, then type: Cd debug, then type this line:hs458.exe change out 1 z . I’ve only just learnt I/O so I’m not sure ... after that I open the debug directory and open the Out file .. in that there’s some numbers and at the end there’s two z’s. Is this what I’m supposed to see? sorry if my questions seem stupid ... |
Recent GIDBlog
NARMY by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| C++ PhoneBook | marita | CPP / C++ Forum | 46 | 12-Jun-2005 12:10 |
| Error C2146: syntax error : missing ',' before identifier 'C4' | mattchew008 | CPP / C++ Forum | 2 | 19-Dec-2004 06:06 |
| type* identifier or type *identifier for pointers? | BobbyMurcerFan | C Programming Language | 3 | 07-Dec-2004 07:41 |
| How Do i get php to find out the file type of a file for me? | viperman95833 | MySQL / PHP Forum | 2 | 08-Mar-2003 09:48 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The