SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 270 | Next

Shon Harris, Allen Harper, Chris Eagle, and Jonathan Ness

"Gray Hat Hacking, Second Edition"

There are two ways to place comments in code: //, or /*and */. The // indicates
that any characters on the rest of that line are to be treated as comments and not
acted on by the computer when the programexecutes. The /*and */ pair start and end
blocks of comment that may span multiple lines. The /*is used to start the comment,
and the */is used to indicate the end of the comment block.
Sample Program
You are now ready to review your first program. We will start by showing the program
with // comments included and will follow up with a discussion of the program.
//hello.c //customary comment of program name
#include //needed for screen printing
main ( ) { //required main function
printf("Hello haxor"); //simply say hello
} //exit program
This is a very simple program that prints ???Hello haxor??? to the screen using the printf
function, included in the stdio.h library. Now for one that??™s a little more complex:
//meet.c
#include // needed for screen printing
greeting(char *temp1,char *temp2){ // greeting function to say hello
char name[400]; // string variable to hold the name
strcpy(name, temp2); // copy the function argument to name
printf("Hello %s %s\n", temp1, name); //print out the greeting
}
Gray Hat Hacking: The Ethical Hacker??™s Handbook
126
Chapter 6: Programming Survival Skills
127
PART III
main(int argc, char * argv[]){ //note the format for arguments
greeting(argv[1], argv[2]); //call function, pass title & name
printf("Bye %s %s\n", argv[1], argv[2]); //say "bye"
} //exit program
This program takes two command-line arguments and calls the greeting() function,
which prints ???Hello??? and the name given and a carriage return.


Pages:
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282