Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 10:55

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Integer out of ARGV Pointer

Discussion on Integer out of ARGV Pointer within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1


 
nicileie's Avatar
 
elite*gold: 1000
Join Date: Aug 2015
Posts: 47
Received Thanks: 14
Integer out of ARGV Pointer

Hello Community,

i am currently working (more testing) coding on C.
Actually i run in the following issue:

I got an storage error, when trying to save an integer, converted out of an Pointer. I googled this and the other dudes do the same and.. it works lol.

Would be glad if you could take a look. No Compile Errors.

Code:
int main(int argc, char **argv)
{
	utilInit(argv[0]);
	int port = 8111;
	if(argc > 1)
	{
		if(strcmp(argv[1], "-p") == 0)
		{
			if(isdigit(argv[2])){
				int port = ntohs(argv[2]);
			}
		}
	}
	infoPrint("Chat Server running on Port: %i", port);
	const int result = connectionHandler((in_port_t)port);

	return result != -1 ? EXIT_SUCCESS : EXIT_FAILURE;
}
When i exclude "int port = ntohs(argv[2]);" it´s working fine.

Thanks.
nicileie is offline  
Old 05/20/2021, 14:06   #2


 
Jeoni's Avatar
 
elite*gold: 966
Join Date: Apr 2010
Posts: 1,105
Received Thanks: 681
The problem is that you have two variables named "port" instead of one. One is declared at the top and initialized with 8111 and the other is declared where ntohs is used. Since the scope of the latter is only in that "if (isdigit..." block, the print function refers to the first one.
Solution: don't declare a new variable. Just leave out the type ("int") when you assign the result of "ntohs".
Jeoni is offline  
Old 05/20/2021, 15:05   #3


 
nicileie's Avatar
 
elite*gold: 1000
Join Date: Aug 2015
Posts: 47
Received Thanks: 14
Yeah, already got that. Thanks.
My Main issue was: "isdigit" doesnt check the whole String Pointer, it´s just 1 Character check. Works now.
nicileie is offline  
Reply


Similar Threads Similar Threads
[VB] integer wird nicht erhöht?!
11/16/2012 - .NET Languages - 4 Replies
Hi, ich hab ein klinens Problem mit meinem "Übersprungen" -Label. ich will das es sich immer um 1 erhöht, wenn das oder das passiert. Nun läuft es in einer For -Schleife die z.B: 3 mal durchläuft aber das "Übersprungen" -Label nur 1 anzeigt obwohl es "3" anzeigen sollte. Hier der Code: Dim übersprungen As Integer Dim count As Integer Application.DoEvents() count = (anzahl_dateien - 1) - I lbl_datei.Text = dateiname(I)
Convert string to integer, Frage...
08/10/2012 - C/C++ - 3 Replies
Hallo, also, es geht um zwei Codes. Beide sollen einen String in eine Zahl umwandeln. Um zu zeigen worum es genau geht, hier der funktionierende Code: #include <iostream> #include <string> #include <sstream> int main () { std::string age;
Integer übertragen?(WndField -> Mover)
06/25/2012 - Flyff Private Server - 9 Replies
hey leute ich arbeite an meinem glow change system un zwar habe ich das fenster schon dort ist ein integer der "fuckingnolife" (name ist egal) heißt dessen wert soll von der WndField.cpp zur Mover.cpp CMover::CreateAbilityOption_SetItemSFX( int nAbilityOption ) übertragen werden. Nur wie soll man das anstellen und hier mal dies ausschnitte WndField.cpp
c++ WinApi integer ausgeben
11/26/2011 - C/C++ - 8 Replies
Hay, also ich bin nun neu in der WinApi mit c++ und versuche mich grad an einem einfachen Rechner(ohne WinApi natürlich kein Problem). Wie im Titel steht schaffe ich es nicht per "TextOut" oder per "MessageBox" einen integer ausgeben zu lassen. Ich hab schon gegooglet etc. bloß bin ich daraus nicht sehr viel schlauer geworden. Bis jetzt hab ich halt das(Ausschnitt): ...
'$' vor einen integer wert adden
12/07/2005 - General Coding - 3 Replies
folgendes: ich habe einen wert welchen ich per RPM ausgelesen habe diesen habe ich per inttohex konvertiert nach dem konvertieren bekomme ich mein gewünschtes offset auf das ich wieder per rpm/wpm zugreifen will da man, soweit ich weiss, bei rpm/wpm ein &#036; vor das offset schreiben muss brauche ich nun eine methode wie ich dieses zeichen vor das offset bekomme habe gestern schon mit dem befehl insert und copy gearbeitet, leider ohne erfolg.



All times are GMT +2. The time now is 10:55.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.