What type of variable should i use on a windows program to store an IP adress (xxx.xxx.xxx.xxx)? And what should i use to store a host address (xxxx.xxxxxxx.xxxxxx.net)?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Don't forget that of you assign memory for a string you must also add one byte for the null terminator.
e,g,
char *pszBuffer = NULL;
pszBuffer = malloc(strlen("xxx.xxx.xxx.xxx")+1);
however, you would normally only use malloc if the memory you required was going to change frequently. With a fixed length string you can just use an array.
e,g,
char pszBuffer[16];
BlakJak :]
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
When it comes to ip addresses you always know at least the biggest size theyll get (12 numbers, 3 points and a null terminator=16), but for hosts youd better use malloc anyway.
I have a program that im working on and i had a simmilar problem, except that in my case, the user can fill the fields with a host or ip address. In that case i decided to make it iporhost[50] just in case.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What type of variable should i use on a windows program to store an IP adress (xxx.xxx.xxx.xxx)? And what should i use to store a host address (xxxx.xxxxxxx.xxxxxx.net)?
char *pszBuffer = NULL;
pszBuffer = malloc(strlen("xxx.xxx.xxx.xxx"));
Don't forget that of you assign memory for a string you must also add one byte for the null terminator.
e,g,
char *pszBuffer = NULL;
pszBuffer = malloc(strlen("xxx.xxx.xxx.xxx")+1);
however, you would normally only use malloc if the memory you required was going to change frequently. With a fixed length string you can just use an array.
e,g,
char pszBuffer[16];
BlakJak :]
When it comes to ip addresses you always know at least the biggest size theyll get (12 numbers, 3 points and a null terminator=16), but for hosts youd better use malloc anyway.
I have a program that im working on and i had a simmilar problem, except that in my case, the user can fill the fields with a host or ip address. In that case i decided to make it iporhost[50] just in case.