I'm not going to -1 cookie you because this
is the noob programming forum
but I almost did on accident.
Now, let me first say that your main function should return an integer. I don't care what tutorial site said what or why they said that, but this is convention. Your main function should return 0 if it was sucessful and if something messes up (like your program isn't given enough command line arguments or somthing) then you return a nonzero integer. There are "better" ways to do this with functions like exit, perror, etc.. but returning a nonzero integer will be fine for now.
Also you should look into what a proper coding style is, pick one you like, and follow it. I'd recommend looking at
this wiki category on general rules of thumb and
this wiki article on code style. (Although you might find more information on coding styles by googling them yourselves.)
Also, excessive printf's aren't the way to go all the time. Like I wrote above, if you'd like to impliment different "options" it's best to do them through command line switches. I'll write some basic command line argument code below just so you can kind of see what's going on.
#include <stdio.h>
/* Our example program is going to take 2 arguments "ip" and "port" */
int main(int argc, char **argv)
{
char *ip;
char *port;
if (argc != 3) {
/* Notice I'm writing to stderr instead of stdout (if you don't know what these are,
* you can google them very easily) this is to distinguish between regular and
* error messages. */
fprintf(stderr, "Usage: ./program <ip> <port>\n");
return 1;
}
/* argv is a list of the command line arguments. argc (as shown above)
* is the argument "count" and is useful for checking to see if the user has
* provided enough arguments. REMEMBER: you must verify the format of
* the arguments are correct. I haven't included this in this snip of code,
* but it'd definitely important if you plan on passing user input through system!
* (passing user defined data through system is a terrible idea, i'd recommend
* staying faaar away from system() unless you're just messing around with it
*/
ip = argv[1];
port = argv[2];
printf("Your two arguments are `%s` and `%s`\n", ip, port);
/* We've made it to the end of the program and we missed the argc error! We can safely
* return 0 and go on our way. */
return 0;
}
If you have any other questions about this sort of coding style (using command line arguments instead of an interactive UI) please ask. As far as the posted code goes, it's cool you're getting into syscalls, check out <unistd.h> for other syscall wrappers or alternatively <sys/types.h> and <sys/syscall.h> if you want raw syscall action.
I've also been looking into different linux syscalls and i noticed you included <Windows.h> so i can tell you're probably on windows. In that case I feel like everything I've typed might be incorrect (I really don't know how to program on windows) but I'd suggest getting a debian VM or something if you aren't dual booting at the moment just to begin using things like man pages and Linux syscalls.
I feel like I've rambled a bit but if I've been unclear on anything please ask.