collapse collapse

* Who's Online

  • Dot Guests: 57
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Board Stats

  • stats Total Members: 88
  • stats Total Posts: 11163
  • stats Total Topics: 1699
  • stats Total Categories: 4
  • stats Total Boards: 76
  • stats Most Online: 248

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Nathan

Pages: 1 2 3 [4] 5 6 7 8 9 ... 46
91
C++ / Re: Writing to Console From A Class?
« on: July 07, 2011, 09:38:47 am »
Shows up for me:
(Visual Studio 2008 Professional, Windows 7 Ultimate x64)
(Attachment Link)
Yeah, I have no idea. Once I put in an escape character for it it worked. Either way, I changed the class declaration since then to be more flexible from player to entity, and one of the params is the char to use.
What compiler/IDE are you using?

92
C++ / Re: Writing to Console From A Class?
« on: July 06, 2011, 11:45:43 pm »
Shows up for me:
(Visual Studio 2008 Professional, Windows 7 Ultimate x64)

93
C++ / Re: pointer + char array = confusion
« on: July 06, 2011, 11:39:29 pm »
I don't think I understand.

But, I'll attempt to explain something.
I believe ** is a multi-dimensional array, what you want to be passing around is char*.
To delete it just do:

delete var;

94
C++ / Re: C++ muitlmap and muitliset
« on: June 20, 2011, 10:18:40 pm »
They are completely different data structures.

Please see these links for examples:
http://advancedcppwithexamples.blogspot.com/2009/04/example-of-c-multimap.html
http://www.cplusplus.com/reference/stl/multimap/

96
General Talk / Terraria
« on: June 12, 2011, 01:21:40 pm »
Anyone else play it? I am very addicted to it. If anyone is interested I could put up a permanent server :).

I started a large/advanced map myself.

If you don't have it - it's only $9.99 off of steam very cheap for a game with high replay value and lifetime updates.

97
Request A Program or Tutorial / Re: Reverse Engineering
« on: May 31, 2011, 08:51:30 pm »
Can you point me in the right direction to get this going? I will probably end up quitting but who knows, maybe with enough time I can do it.  What language is that program in, etc?
Considering its a commercial product we really can't help you. There are reverse engineering tutorials on this site, but we won't hold your hand to crack a commercial product.

98
php / Re: Calculator[Simple]
« on: May 21, 2011, 10:25:34 am »
You should not use $_REQUEST, in this case you should use $_POST.

http://php.net/manual/en/reserved.variables.request.php

99
Visual Basic / Re: Reading user from database
« on: May 20, 2011, 08:12:14 am »
Code: Visual Basic
  1. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" ( _
  2. ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  3. Private Const GWL_EXSTYLE = (-20)
  4. Private Const WS_EX_TRANSPARENT = &H20&
  5.  
  6. Dim retCode As Long
  7.  
  8. Const ERROR_SUCCESS = &H0
  9. Const HWND_TOPMOST = -1
  10. Const HWND_NOTOPMOST = -2
  11. Const SWP_NOSIZE = &H1
  12. Const SWP_NOMOVE = &H2
  13. Const SWP_NOACTIVATE = &H10
  14. Const SWP_SHOWWINDOW = &H40
  15.  
  16. Dim Timer
  17.  
  18. Dim Counter As Integer
  19.  
  20. Dim regkey As Integer
  21.  
  22. Dim Amount As String
  23.  
  24. ' Access the GetCursorPos function in user32.dll
  25.      Private Declare Function GetCursorPos Lib "user32" _
  26.       (lpPoint As POINTAPI) As Long
  27.  
  28.       ' GetCursorPos requires a variable declared as a custom data type
  29.      ' that will hold two integers, one for x value and one for y value
  30.      Private Type POINTAPI
  31.          X_Pos As Long
  32.          Y_Pos As Long
  33.       End Type
  34.  
  35.       ' Main routine to dimension variables, retrieve cursor position,
  36.      ' and display coordinates
  37.      Sub Get_Cursor_Pos()
  38.  
  39.       ' Dimension the variable that will hold the x and y cursor positions
  40.      Dim Hold As POINTAPI
  41.  
  42.       ' Place the cursor positions in variable Hold
  43.      GetCursorPos Hold
  44.      
  45.       Beep
  46.  
  47.       ' Display the cursor position coordinates
  48.      MsgBox "X Position is : " & Hold.X_Pos & Chr(10) & _
  49.          "Y Position is : " & Hold.Y_Pos
  50.      
  51.       Beep
  52.       MsgBox ("You have 1 minute to correctly enter your details!")
  53.      
  54.       End Sub
  55.    
  56. Private Sub C1_Click()
  57.  
  58. If User.Text <> "" Then User.Text = ""
  59. If Pass.Text <> "" Then Pass.Text = ""
  60.  
  61. End Sub
  62.  
  63. Private Sub Form_Load()
  64.  
  65. Dim tim As Integer
  66.  
  67. tim = 3
  68.  
  69. '// if the registry key date is not = to 3 days
  70.  
  71. If tim <> 3 Then
  72.  
  73. '// show abusive login warning
  74.  
  75. Beep
  76. MsgBox ("Your lockdown time is not up for another " & lockdown & " days!")
  77.  
  78. '// show goodbye message
  79.  
  80. Beep
  81. MsgBox ("Goodbye!")
  82.  
  83. '// end program
  84.  
  85. End
  86.  
  87. Else
  88.  
  89. '// set the counter default
  90.  
  91. Counter = 3
  92.  
  93. '// change the password field to *
  94.  
  95. Pass.PasswordChar = "*"
  96.  
  97. '// get external IP
  98.  
  99. Dim strSourceCode As String
  100. strSourceCode = Inet1.OpenURL("http://98.227.253.56./Secure./")
  101.  
  102. '// set the ip caption to the IP
  103.  
  104. IP.Caption = strSourceCode
  105.  
  106. Dim strMyComputerIP As String
  107.  
  108. strMyComputerIP = Winsock1.LocalIP
  109.  
  110. Label4.Caption = strMyComputerIP
  111.  
  112. Top = (Screen.Height - Width) \ 2
  113. Left = (Screen.Width - Width) \ 2
  114.  
  115.      Timer1.Interval = 1000
  116.      Label1.Caption = "60"
  117.          
  118.      Timer = Label1.Caption
  119.      
  120.     Beep
  121.     MsgBox ("Welcome to the Kingdom Of Jewels Authenticator!" & vbCrLf & vbCrLf & "You have " & Timer & " seconds to login to your account!" & vbCrLf _
  122.     & "Otherwise, you will be temporarily locked out of the updater for security purposes!")
  123.  
  124. End If
  125.  
  126. End Sub
  127.  
  128. Private Sub Login1_Click()
  129.  
  130. '// create global variables
  131.  
  132. Dim ConnMySql As New ADODB.Connection
  133.  
  134. Dim db, tbl, num
  135.  
  136. '// define global variables
  137.  
  138. db = "Gn0sis001"
  139.  
  140. tbl = "accounts"
  141.  
  142. '// open a MySQL connection
  143.  
  144. ConnMySql.Open "DRIVER={MySQL ODBC 3.51 Driver};" _
  145.             & "SERVER=localhost;" _
  146.             & "DATABASE=" & db & ";" _
  147.             & "UID=root;" _
  148.             & "PWD=Gen0sis;" _
  149.             & "ENCRYPT=1" _
  150.             & "OPTION=" & 1 + 2 + 8 + 32 + 2048 + 16384
  151.            
  152. '// drop the table if it already exists and create a new 1
  153.            
  154. ConnMySql.Execute "DROP TABLE IF EXISTS `" & tbl & "`;"
  155. ConnMySql.Execute "CREATE TABLE `" & tbl & "`(" _
  156.            & "id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY," _
  157.            & "user VARCHAR(32) NOT NULL," _
  158.            & "pass VARCHAR(32) NOT NULL," _
  159.            & "ip VARCHAR(15) NOT NULL" _
  160.            & ");"
  161.  
  162. '// if the database exists, and the table was created, then use the database
  163.  
  164. ConnMySql.Execute "USE `" & db & "`;"
  165.  
  166. '// if you successfully connected
  167.  
  168. If ConnMySql.State = 1 Then
  169.  
  170. '// show a messagebox saying you connected
  171.  
  172.     Beep
  173.    
  174.     MsgBox ("Connected successfully to database: " & db & "!" & vbCrLf _
  175.           & "Connected to table: " & tbl & "!")
  176.    
  177. '// otherwise
  178.  
  179. Else
  180.  
  181. '// show a messagebox saying you did not connect
  182.  
  183.     MsgBox ("Failed to connect to database!")
  184.  
  185. End If
  186.  
  187. '// if they are connected then check the string
  188.  
  189. If ConnMySql.State = 1 Then
  190.  
  191.       '// compare user string to database string
  192.    
  193.         If User.Text <> "" Or Pass.Text <> "" Or User.Text <> "null" Or Pass.Text <> "null" Then
  194.        
  195.       '// select user from accounts
  196.        
  197.         sqlcommand = "SELECT `user` FROM " & tbl
  198.        
  199.       '// execute above command
  200.    
  201.         ConnMySql.Execute (sqlcommand)
  202.            
  203.         Beep
  204.        
  205.       '// debug - call messagebox
  206.        
  207.         MsgBox (sqlcommand)
  208.        
  209.       '// if the user text is equal to 1 of the usernames in the database
  210.        
  211.         If User.Text = ConnMySql.Execute(sqlcommand) Then
  212.        
  213.       '// send string to the server telling it you entered the right username
  214.      
  215.       sqlcommand = "INSERT INTO `user` ( " _
  216.       & "`locked` VALUES(0);"
  217.      
  218.       ConnMySql.Execute (sqlcommand)
  219.            
  220.       '// end
  221.            
  222.         End If
  223.                    
  224.             '//if none of the strings match the database strings, or one or both are nothing, then decrease the counter by 1
  225.          
  226.            Counter = Counter - 1
  227.            
  228.            '// do not let the counter exceed 1
  229.  
  230.             If Counter <= 0 Then Counter = 0
  231.                        
  232.             '// If the counter is > 0 and user.text is not empty and password is not empty
  233.                
  234.                 If Counter > -1 Then
  235.                
  236.                 '// if the user text is Test and the pass text is Test
  237.                
  238.                     If User.Text = "Test" And Pass.Text = "Test" Then
  239.                    
  240.                     '// execute SELECT FROM WHERE clause
  241.                        
  242.                         ConnMySql.Execute "SELECT user,pass FROM " & tbl & " WHERE `user`='" & User.Text & "' AND `pass`='" & Pass.Text & "';"
  243.                    
  244.                     '// Show it in a messagebox
  245.                    
  246.                         Beep
  247.                         MsgBox ("SELECT user,pass FROM " & tbl & " WHERE `user`='" & User.Text & "' AND `pass`='" & Pass.Text & "';")
  248.                
  249.                     '// you got it right, reset the counter
  250.                    
  251.                        Counter = 3
  252.                
  253.                 '// otherwise
  254.                
  255.                 Else
  256.                
  257.                         User.Text = ""
  258.                         Pass.Text = ""
  259.                                                
  260.                 '// correct the spelling
  261.            
  262.                 If Counter = 1 Then
  263.                     Amount = "TIME"
  264.                 Else
  265.                     Amount = "TIMES"
  266.                 End If
  267.                
  268.                     '// if the counter is > 0
  269.                    
  270.                     If Counter > 0 Then
  271.                    
  272.                     '// you got an incorrect login, show in messagebox
  273.                    
  274.                         Beep
  275.                                                    
  276.                         MsgBox ("INCORRECT LOGIN! YOU HAVE " & Counter & Amount & " LEFT!")
  277.                        
  278.                     End If
  279.                    
  280.                 End If
  281.                            
  282.             End If
  283.            
  284.        End If
  285.                                
  286.  End If
  287.  
  288. '// reset the variables
  289.                    
  290. User.Text = ""
  291. Pass.Text = ""
  292.  
  293. '// if counter = 0 then disable the form
  294.  
  295.     If Counter = 0 Then
  296.     Welcome.Enabled = False
  297.     IP.Enabled = False
  298.     User.Enabled = False
  299.     Pass.Enabled = False
  300.     Login1.Enabled = False
  301.     C1.Enabled = False
  302.     Label2.Enabled = False
  303.     Timer1.Enabled = False
  304.     Label1.Enabled = False
  305.     Label2.Enabled = False
  306.     Label3.Enabled = False
  307.     Label4.Enabled = False
  308.     Exc.Enabled = False
  309.            
  310. '// show abusive login use message
  311.    
  312.     MsgBox ("Sorry, but you have been locked out for 3 days for abusive login use.")
  313.        
  314.     End If
  315.    
  316. End Sub
  317.  
  318. Private Sub Timer1_Timer()
  319.  
  320.  '// if time is up, then lock form
  321.  
  322.      If Label1.Caption = 0 Then
  323.      
  324.           Welcome.Enabled = False
  325.           IP.Enabled = False
  326.           Exc.Enabled = False
  327.           User.Enabled = False
  328.           Pass.Enabled = False
  329.           Login1.Enabled = False
  330.           C1.Enabled = False
  331.           Label2.Enabled = False
  332.           Timer1.Enabled = False
  333.           Label1.Enabled = False
  334.          
  335.   '// show times up message
  336.          
  337.           Beep
  338.           MsgBox ("Sorry, but time is up. You have been locked out for 3 days!")
  339.          
  340.   '// show goodbye message
  341.          
  342.           Beep
  343.           MsgBox ("Goodbye!")
  344.          
  345.   '// end program
  346.          
  347.           End
  348.          
  349.   '// otherwise
  350.    
  351.      Else
  352.      
  353.   '// continue count down
  354.    
  355.           Label1.Caption = Label1.Caption - 1
  356.      
  357.      End If
  358.  
  359. End Sub
  360.  
I know this is a dumb question - but it doesn't seem like you actually check to see if a database connection is made.
Also, this seems like VB6, you may want to think about using VB.Net (which is free).

100
OpenGL / Re: SDL segfault on SDL_Flip()
« on: May 08, 2011, 10:05:30 am »
Okay so i get a segfauly when i try to flip the screen to update. im not sure why..
I dont really want to post my code because its a few hundred lines and really now way to slim it down. but what could cause this??
Thanks
You could attach it as a file.

101
Software support / Re: lithtech game engine
« on: May 04, 2011, 11:01:43 pm »
That is a commercial engine and as such is not free to use. You cna only get it from questionable sources.
I believe the old versions were open sourced, at least I'm pretty sure the engine for Blood 2 was.

102
General / Re: Creating A File That is Also A Filesystem
« on: May 04, 2011, 08:05:39 am »
In this short tutorial you'll learn how to create a file with the terminal and turn it into a filesystem of it's own. (y'know, hide that porn)

What you'll need:

1. A *nix system
2. A terminal
3. Sudo access(for mounting)

I can't promise it'll work exactly the same in all distros.

First, we need to create a file full of null blocks, to do this we enter this command(directory is irrelevant):

Code: [Select]
dd if=/dev/zero of=whateveryouwant bs=1000k count=10
Change the of parameter and bs to whatever you like. Bs 1000k will create a 10MB file.

Code: [Select]
mke2fs whateveryounamedyourfile
Before you can mount it, make sure you have a directory ready from which you can access your new filesystem.

Code: [Select]
sudo mount -o loop whateveryounamedyourfile whateverdirectorytomountto
I don't really know much use for this really unless you want to hide files, but I thought it was kinda cool.
You can use that mount with loop to mount disk images created by dd or dd_rescue.

103
Updates / New backup system
« on: May 03, 2011, 09:56:52 pm »
FINALLY!

I got the 6TB of storage setup, and installed a backup software called backuppc. While I have configured it to back up other servers, the important part is that it is backing up this server about every 4 hours (previously once/24 hours), and MySQL dumps happens every 8 hours, at least until I can clean up the old unused websites (instead of the previous once/24 hours). Backuppc also allows supports incremental backups so now my data storage requirements should drop dramatically. And it is easy to view previous versions, as well as downloading a snapshot at a particular time.
I also have an account at http://www.onlinestoragesolution.com/ and while they appear to be suspicious, I have an account with the ability to upload files (which means that it doesn't seem to be a scam) so I plan on downloading a snapshot every once and a while (probably once a month), encrypting it, and uploading it offsite to at least have something in case of fire/flood/2012 apocalypse. If they do disappear off the face of the planet, then I'll figure out a different "solution" but that should work for awhile.

I am currently in the process of transferring the data off of spare harddrives to use in another RAID array.

And closing - Justin I really want to help you with coding, and it is on my to-do list to get it working on Mac/Linux...unfortunately being a "Super System Administrator" tends to take priority :(. I just wish I knew people who lived around me who I could easily get up to speed on my infrastructure and trust both at a console and not going to snap and destroy what I worked hard to build :).

Edit - I should mention that while dumping the database during the day isn't the best idea, but my next plan of attack is to P2V this environment and add another MySQL server on the network that replicates this one so I can dump the db on the server all day without, in theory, affecting this system.

104
Updates / NAS setup
« on: April 30, 2011, 06:01:49 pm »
I settled for the Netgear ReadyNAS NV+ (4 disks @ 2TB each w/ X-RAID), I couldn't get the towerraid to work and the RAID card that came with it wasn't stable (claimed disks where in an array when I couldn't remove them)



When I get the time/money I'm going to give this a spin and see how well it works:
http://www.amazon.com/Mediasonic-3-5-Inch-eSATA-Enclosure-HF2-SU2S2/dp/B002UUPWP6/ref=pd_sim_e_2

I'll also be setting up BackupPC ( http://backuppc.sourceforge.net/info.html#screenShots ) as a "proper" backup system (instead of Nathanware scripts).

105
C++ / Re: 3D FPS Walkthrough
« on: April 26, 2011, 09:05:07 pm »
Video 1 has been uploaded. The software I was using does not like OpenOffice's powerpoint feature, so it crashed mid record. I patched the video with a new recording, but it is painfully obvious after a few minutes in where it happened. This video is in low quality since it is a powerpoint only for the first one. Anyhow, enjoy.
I would be willing to help out, I can purchase a high quality headset and my system is more than enough to do development.

Could you do the Nix version of the code? We can get by using defines. I can prep it as well as I am able for you to come in later. Aside from that though, I don't really see how you could help out (although I'd love the help).




*Removed youtube tags for quote. - Celestialkey
I could do the Linux and/or Mac code and packaging. Of course if you give me something to work off of that would be the best.

106
C++ / Re: 3D FPS Walkthrough
« on: April 26, 2011, 07:22:40 pm »
Video 1 has been uploaded. The software I was using does not like OpenOffice's powerpoint feature, so it crashed mid record. I patched the video with a new recording, but it is painfully obvious after a few minutes in where it happened. This video is in low quality since it is a powerpoint only for the first one. Anyhow, enjoy.
I would be willing to help out, I can purchase a high quality headset and my system is more than enough to do development.






*Removed youtube tags for quote - Celestialkey

107
C++ / Re: using dll and equivilents in 1 source file
« on: April 11, 2011, 01:57:59 pm »
What I do is use a define to prototype functions for each type of OS. That way, you can use the common defined one, and the compiler automatically replaces all instances with the proper version.

Code: C++
  1. #ifdef _WIN32_
  2.     #define GetTheKey GetAsyncKeyState
  3. #else ifdef __NIX
  4.     #define GetTheKey _SDLCallKeyFunct
  5. #else
  6.     #define GetTheKey _MacOSXKeyFunction
  7. #endif
That probably would only work if the functions had the same parameters and return data. Probably something more like:

Code: C++
  1. char key;
  2. #ifdef _WIN32_
  3.     key = GetAsyncKeyState(..)
  4. #else ifdef __NIX
  5.     key = _SDLCallKeyFunct(..)
  6. #else
  7.     key =  _MacOSXKeyFunction(...)
  8. #endif
  9. return key;

108
C++ / Re: problem with linker in code::blocks with SFML
« on: April 09, 2011, 09:17:02 am »
I still am getting the same error even after i install SFML from the package manager..
Did you follow these instructions and replace hardy with your version of Ubuntu?
http://www.sfml-dev.org/wiki/en/tutorials/getdebpackage

109
C++ / Re: Best Graphics Library For Beginners?
« on: April 08, 2011, 10:44:32 am »
So my neighbor decided he would try to become a game programmer after college, I agreed to help him get started in programming(most likely today). Even though it's going to be a while before he's actually ready to get into graphics, which library should I recommend he start with? I'd like to know so it can give me some time to figure it out myself, being that I've never really had much interest in programming(non-text based) games myself.

    ~Samo502
Irrlicht, Panda3D, DirectX, or even BASIC (FreeBASIC).
I think Visual Studio includes a free version of DarkGDK.

110
Code Snipplets / Re: Codepad
« on: April 03, 2011, 05:53:46 pm »
I came across this cool site called codepad. It allows you to paste code which the site then (depending on the language) compiles/interprets and runs, and gives you the results. Supported languages are C, C++, D, Haskell, Lua, OCaml, PHP, Perl, Python, Ruby, Scheme, and Tcl.

Obviously for security reasons some features of the languages are disabled (like system() and I think anything that uses sockets), but if you're just wanting to try something out real quick, or get to know a new language without installing big compiler/interpreter bundles, this is just great.

http://codepad.org/about
That is actually pretty cool and something similar I want to do at some point.

111
C++ / Re: first char of a string to a unsigned char?
« on: April 03, 2011, 05:51:12 pm »
There's string::at. It's zero indexed, so to get the first character of string s, you'd do s.at(0).

How do you convert it to ASCII or unsigned char?
at returns a char
http://www.cplusplus.com/reference/string/string/at/

112
That's fairly easy - just call the Windows API to make a Window without a title bar.

This should do nicely:
http://msdn.microsoft.com/en-us/library/ms632680(v=vs.85).aspx

113
General / Re: Do you compiler your own Linux Kernel?
« on: April 02, 2011, 12:52:16 pm »
I really doubt that you will get that much of a speed increase from it. And even if you do - it's more hassle than its worth. Especially considering you have to recompile every time a new kernel version comes out.
Actually you can get the kernel to be quite a bit faster and leaner than in most binary distributions. You can get rid of initrd, most of the unneeded drivers, and you can try out BFS or some other crazy patches that might not be the stablest thing out there, but can yield a noticeable performance increase on certain tasks.

There's also make oldconfig which allows you to migrate from older kernel's .config to the newer, only changing if something new was added, or if something was marked stable instead of experimental, and so on. So in reality upgrading is quite easy and painless.

But yeah, still I'd say the init/rc system and other software you use matters more, especially when considering the general speed and performance of the system, not just startup.

Size is another thing why some people might want to do it, especially on embedded and other systems where smaller is better. I used Gentoo for a few years and had gotten used to having a boot partition of 16 megs. Then I switched to Ubuntu without resizing any partitions, and was quite surprised to find out that apt would run out of free space on /boot when installing a new kernel.. I'd have to manually remove the old kernel before installing a new one, and could only have one kernel version installed at a time. With Gentoo and my own kernels the final kernel images were generally around two megabytes, so potentially I could've installed up to eight different kernels on /boot. Usually I kept kernel images from two or three versions ago in case of regressions or anything.
I remember awhile back Ubuntu wanted a 10 second boot up time in 10.04. In fact this guy has his laptop boot up in 8.6 seconds: http://www.jamesward.com/2010/09/08/ubuntu-10-10-boots-in-8-6-seconds/

For the average user and the amount of time learning how to do vs the slight speed increase, I don't think it would be worth it.

114
General / Re: Do you compiler your own Linux Kernel?
« on: April 02, 2011, 09:12:05 am »
Do you compiler your own Linux Kernel?
You should at least try once, and it boots up faster and it is more efficient.
but listing all the modules is a pain...
I really doubt that you will get that much of a speed increase from it. And even if you do - it's more hassle than its worth. Especially considering you have to recompile every time a new kernel version comes out.

115
C++ / Re: Get ASCII value of a char?
« on: April 01, 2011, 08:07:09 am »
Seems like Nathan is a bit confused, as atoi doesn't do what you want. It's used to convert from a string to a number. Take this for example:
Code: C++
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(void)
  5. {
  6.     char str[] = "42";
  7.  
  8.     printf("%%s with str[]: %s\n" /* This will print 42, str is being used as a string */
  9.            "%%d with str[]: %d\n" /* Undefined behavior. str is used as an integer, but in reality it's still a character array */
  10.            "%%d with atoi(str): %d\n", /* This will print 42. atoi() converts the string into an integer, and it's being used as an integer */
  11.            str, str, atoi(str));
  12.  
  13.     return 0;
  14. }
  15.  
  16.  

When we compile it we already get a warning;
Code: [Select]
jh@zebra437:~$ gcc -Wall -o atoi atoi.c
atoi.c: In function ‘main’:
atoi.c:11: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘char *’
Argument 3 is where we use the string as an integer.

When we run it, the results of the first and third lines are correct but the second line is not. In fact it isn't even constant, as we can see if we run it multiple times.
Code: [Select]
jh@zebra437:~$ ./atoi
%s with str[]: 42
%d with str[]: 406641888
%d with atoi(str): 42
jh@zebra437:~$ ./atoi
%s with str[]: 42
%d with str[]: 847314928
%d with atoi(str): 42
jh@zebra437:~$ ./atoi
%s with str[]: 42
%d with str[]: -273827344
%d with atoi(str): 42
jh@zebra437:~$ ./atoi
%s with str[]: 42
%d with str[]: 961454688
%d with atoi(str): 42

The difference between the first and third line becomes apparent when we want to do something with our input.
Code: C++
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(void)
  5. {
  6.     char str[] = "42";
  7.     printf("42 + 1 = %s\n", str+1);
  8.     return 0;
  9. }
  10.  
This will not print 43 as expected, but something else because you're trying to add the number 1 to a string, an action that doesn't make any sense.
Code: [Select]
jh@zebra437:~$ ./atoi
42 + 1 = 2

But when we add in atoi, it'll work as expected.
Code: C++
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(void)
  5. {
  6.     char str[] = "42";
  7.     printf("42 + 1 = %d\n", atoi(str)+1);
  8.     return 0;
  9. }
  10.  
Output:
Code: [Select]
jh@zebra437:~$ ./atoi
42 + 1 = 43

So yes, it's a neat little function but doesn't help you in any way to get the numerical value of a character. For that you'll want what Justin said:
Code: C++
  1. #include <stdio.h>
  2.  
  3. int main(void)
  4. {
  5.     printf("The character value of 97 is %c\n"
  6.            "The numeric value of 'c' is %d\n",
  7.            (char)97, (int)'c');
  8.     return 0;
  9. }
  10.  
  11.  
Code: [Select]
jh@zebra437:~$ gcc -Wall -o cast cast.c
jh@zebra437:~$ ./cast
The character value of 97 is a
The numeric value of 'c' is 99


[edited name=jho date=1301659849][/edited]
Doh! Yeah your right. I misread his question, it got jumbled up in my mind because I actually just did a project which involved atoi and itoa which I needed to know the actual number representation no the ASCII value.

116
C++ / Re: Get ASCII value of a char?
« on: March 31, 2011, 11:07:06 pm »

117
C++ / Re: Get ASCII value of a char?
« on: March 31, 2011, 09:33:28 pm »
Damnit I meant atoi.

118
C++ / Re: Get ASCII value of a char?
« on: March 31, 2011, 08:35:55 pm »
Is there a replacement of itoa in gcc?
Mmmm... Why not just do a simple conversion?
Code: C++
  1. int x= (int)'a';

It works both ways so you can just convert it back via
Code: C++
  1. char x = (char)97;

No need for all that complex stuff. Or is conversions like this not available in gcc? If so, that is amazingly odd...
itoa is available in gcc, it's part of the standard.

119
C++ / Re: Get ASCII value of a char?
« on: March 31, 2011, 07:30:42 pm »
I am using gcc on linux.
How do you get the ASCII value of a char?
Example: ASCII 97 is "a"

Code: [Select]
char blah[2] = { "a" };
and also the other way around ASCII int to char?
Code: [Select]
strcat(blah,char(92)); //why fails?
You mean atoi http://www.cplusplus.com/reference/clibrary/cstdlib/atoi/?

There is also itoa, but its unstandardized though in many compilers. Without knowing what you are doing you could just do something like:

Code: [Select]
char x = 97;

120
Updates / More storage
« on: March 31, 2011, 12:06:31 am »
I made several major purchases towards a more "professional" hosting environment.

TowerRAID 8 Bay eSATA RAID 0/1/10/5/JBOD Performance Tower with 6G PCIe Card TR8M-BP (Black)
http://www.amazon.com/gp/product/B003X0BJCW
$319.99

Vantec 6-Port SATA II 150 PCI Host Card with RAID
http://www.amazon.com/gp/product/B002PX9BX2
$25.67

HDD 2T|SEAGATE ST2000DL003 64M % - OEM
http://www.newegg.com/Product/Product.aspx?Item=N82E16822148681
5 @ $79.99 = $399.95

Total cost (free shipping and no taxes wewt!): $745.61

I plan on purchasing 4 (one spare) more 2TB HDs to expand the RAID but 5 is good to start with which will net me 8TB (with RAID 5). Total size I will get is 14TB (8 disks @ 2TB - 1 disk for hot spare).

The reason why I purchased the 8 bay is because although it has external SATA and no networking, it's about the same price as a 2-4 NAS.
The RAID card was arbitrary, it seemed to have the best rating. And although I know I picked a slower HD (5400 vs 7200), judging from the reviews it doesn't seem to have a higher failure rate as other 2TB drives. Which, I have noticed that the higher capacity drives seem to die sooner than smaller ones, which this could be due to the speed. In the RAID, at this point anyways, I am not concerned about speed I just need capacity as I have hit a wall when it comes to storage. And I need reliable storage - otherwise I would just have purchased a dock and the drives.

Pages: 1 2 3 [4] 5 6 7 8 9 ... 46

Donate


* Search


* Recent Posts

Image Comparison by Shishka
[May 15, 2017, 01:18:02 pm]


Re: srchub - free source code hosting by Nathan
[December 14, 2015, 11:37:02 pm]


Re: srchub - free source code hosting by Celestialkey
[November 27, 2015, 08:51:42 am]


Updates by Nathan
[October 30, 2015, 08:27:36 pm]


Re: Client-Server Messaging by Nathan
[October 25, 2015, 05:48:57 pm]