Allright so to make a long story short im interested in making C programs that execute "CMD commands."Now, my question is, shouldnt i just learn CMD commands. What im saying is, do i really have to learn anthing else in C it self to communicate with the OS than the system() function?I hope im not confusing anyone with my rambling questions...

Well, if all you want to do is run commands for the command prompt then you should just use a batch file. Then you wouldn't have to compile all that VERY unnecessary C code(I guess this could be useful if you wanted an executable file).

do i really have to learn anthing else in C it self to communicate with the OS than the system()

This will only allow you to interact with the command prompt, which is very limited. I'm not sure I know what you mean by "communicate with the OS". The command prompt is very limited and can't really do all that much. The main way to use the OS would be through calling API functions and interrupts. This is much more powerful and can do much more than the command prompt.

shaqywacky wrote:This will only allow you to interact with the command prompt, which is very limited. I'm not sure I know what you mean by "communicate with the OS". The command prompt is very limited and can't really do all that much. The main way to use the OS would be through calling API functions and interrupts. This is much more powerful and can do much more than the command prompt.

Maybe given an example of what you would like to do.

Will do, lets say i want to make a program that gets the IP adress of the computer and then sends it to me. That would be a very simple example, but programs that resemble worms are interesting me at the moment.

That's my output of ipconfig so yours may be a little different. Assuming you only want the first IP address found(there can be multiple IPs for one computer). You would take that output and search for the term 'IPv4 Address' and then use some string manipulation to get the IP at the end. While this solution can get the IP address(although it could have many problems), it is pretty much limited to that.

The way using API functions would be conceptually simpler but probably more difficult at first. The only thing you would have to do is call the necessary API function that can give you the IP address. It would probably give it to you in a structure but it would be trivial to extract it. The reason this may be more difficult at first is because, at least in my experience, the required libraries aren't always standardized and the compiler options can be very specific.

I suggest you do both ways because both will give you very good experience, if you don't feel like doing both, I would recommend the API way because the CMD example can't really do much else. But the API example could then, using APIs, connect to different computers.

I don't think the command prompt can call APIs but if it can, I can guarantee it is much better and easier with C.

One final thing. C network programming can be pretty difficult when you first start. I would REALLY suggest you have a good grasp on the language or be prepared to become very frustrated.

shaqywacky wrote:One final thing. C network programming can be pretty difficult when you first start. I would REALLY suggest you have a good grasp on the language or be prepared to become very frustrated.

I am relatively new to programing in general, with around 4 months of experience over all. I started with FreeBASIC tried it out and made a couple calculators, then moved to C++ for around a month and then finally went to C. Ive only been coding in C for around 2 months, although i will say i am a very fast learner. With that being said, i don't want to skip anything crucial or important in the C language, and especially going into something like C Network Programing while having a hole in my knowledge of C. I am comfortable with if statements, logical operotors{ || and && }, i can manipulate strings,mathematical operators{ *, /, +, -, =, ==}. and i know who to read, write and edit files using C. I don't believe i have missed anything, that is all i know at the moment in C, should i move up to C networking and API, or am i missing somenthing? Oh and one last thing ive been noticing that for more technical things in C its becoming much harder to find usefull websites on these subjects, could you link a good website, or video for things C related. Thankyou

Firstly... Using ipconfig won't give you the IP address that you're looking for. It'll only give you the internal IP, the one that your home network uses to get around. You won't see your external IP address doing it that way. The external is the one that you're probably going to be looking for; it's the one that other computers will use to talk to it.Secondly, if you were just gonna do it that way, you could just output the ipconfig results, and use your string manipulation shizz to get the IP like shaqywacky said. Then you could use that as the input for your C program. But that is a long tedious way, which could help you learn both batch and C.The funner, and maybe even more tedious, way would to add in a web server in there somewhere. You could set up a little apache PHP page on a box somewhere and have your C program on another box visit it. Use your PHP skills to have it output their IP. I think it's something like "echo $_SERVER['REMOTE_ADDR'];" IIRC. Then have your C program use that IP as input. No batch needed, just like a true virus. But in the end, it's all redundant considering you would have to know the IP to have a program on it. The only way I could see someone using this is if they had a some sort of worm that infects shit tons of computers. Each infected computer would report back to your box so you could have their IP for when you need to give them back commands for malicious stuff, say a botnet or something of the like.

and then include in the program a function/method to parse out the ip address in the returned index.html. That is assuming the pc wouldn't be going through any proxies. I've seen programs with wget for windows so I guess it would be possible to do with CMD.

About what you want to do:I suggest after finishing with C, you should start with c++, after finishing C++, you should look on the documentation of Data Structures and algorithms(most of this are implemented in c++, but its best to know how it works, you can read about this after finishing pointers and structs), then you should read something about Design Patterns and Antipatterns.