Wednesday, May 6, 2020
C Programming Essay Example For Students
C Programming Essay C programming for the complete newbieHello there im Krisis you may have seen me on irc.hackersclub.com. Well I thought it was about time to write an article like everyone else. Butunlike many others mine wont be on Hacking, Cracking, or Phreaking its on C programming, yousee Im not the best hacker but Im an ok programmer. So here it goes. This is based for absolutebeginners so those of you like my friend Chrak wouldnt be interested in it. 1st lets talk about some of C s history. C was invent by Dennis Ritchieand KennethThompson. They modeled it after the language they were using called B. Cwas a subset of B hencethe name. C was made because B was going out of style and they needed a newlanguage to write UNIX in. Yes UNIX was made in C. C was made popular very quickly becauseevery UNIX sold had a Ccompiler. A compiler is a program thats looks at your source code andtransfers it into object code, after it is transfered into object code it must be linked, once itslinked it can beexecuted. /***********************************************************************************************/2nd Lets talk about variables they are your integers and characters and soon. You have many data types they are. int integerschar characterslong int bigger integersshort int same as intfloat decimal numbersdouble even bigger decimal numbersTo define a variable 1st you must put something like int MyNum;MyNum = 2;or for a character value it would be like char name; name= Jim;notice the you must have those around character values, they are notneeded for integers ordecimals. /***********************************************************************************************/3rd Ill tell you about stuff like #include and #define. #include is usedto tell the compiler that whatever is in the brackets just be included like its part ofyour code. #include ;stdio.h; #define is used to define something Like the color of a truck or car. #define TRUCK red#include and #define must come before any functions are even prototyped(Ill talk about this later). /***********************************************************************************************/ 4th Ill talk about functions. Every program must have at least onefunction. That functions name must be main(). The () tells the compiler that it is afunction. All functions must return a value in the main() function a 0 is usually returned. In yourfunctions you willwant to use comments to explain your code a comment is begun by using /*and ended by using */ . I will now show you your 1st program. #include stdio.h /* Used in most standard Input Output Programs */main()/* Beginning Brackets used to show the beggining ofa block of code */printf(Hello World); /* A function already written in Stdio.h */return 0; /* Value returned from the program */} /* Ending bracket used to show end of a block of code */now compile your program in your compiler if your using UNIX do it like this gcc hello.c -o Helloand then run your program bye typing in ./Hello/***********************************************************************************************/5th Ill talk about output which is essential to almost all programs. Ill start you out with printf(); It is defined in Stdio.h so every time youcall printf(); you must include Stdio.h . printf(); s syntax is quite easy you just used it like thisprintf(What ever you want outputted);to output variables you do it like this char dog=scruffy;printf(My dogs name is %c, dog); notice the %c it tells the compiler tolook for a character variable. Now for Integers and Decimalsint age=16;printf(I am %d years old, age); use %d to print out decimals and integers /***********************************************************************************************/6th Lets talk about multiple functions. When you have more than one functionyou must prototype it. Here is an example. .ub3c17e4c21f9daf294663e2be60ee707 , .ub3c17e4c21f9daf294663e2be60ee707 .postImageUrl , .ub3c17e4c21f9daf294663e2be60ee707 .centered-text-area { min-height: 80px; position: relative; } .ub3c17e4c21f9daf294663e2be60ee707 , .ub3c17e4c21f9daf294663e2be60ee707:hover , .ub3c17e4c21f9daf294663e2be60ee707:visited , .ub3c17e4c21f9daf294663e2be60ee707:active { border:0!important; } .ub3c17e4c21f9daf294663e2be60ee707 .clearfix:after { content: ""; display: table; clear: both; } .ub3c17e4c21f9daf294663e2be60ee707 { display: block; transition: background-color 250ms; webkit-transition: background-color 250ms; width: 100%; opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; background-color: #95A5A6; } .ub3c17e4c21f9daf294663e2be60ee707:active , .ub3c17e4c21f9daf294663e2be60ee707:hover { opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; background-color: #2C3E50; } .ub3c17e4c21f9daf294663e2be60ee707 .centered-text-area { width: 100%; position: relative ; } .ub3c17e4c21f9daf294663e2be60ee707 .ctaText { border-bottom: 0 solid #fff; color: #2980B9; font-size: 16px; font-weight: bold; margin: 0; padding: 0; text-decoration: underline; } .ub3c17e4c21f9daf294663e2be60ee707 .postTitle { color: #FFFFFF; font-size: 16px; font-weight: 600; margin: 0; padding: 0; width: 100%; } .ub3c17e4c21f9daf294663e2be60ee707 .ctaButton { background-color: #7F8C8D!important; color: #2980B9; border: none; border-radius: 3px; box-shadow: none; font-size: 14px; font-weight: bold; line-height: 26px; moz-border-radius: 3px; text-align: center; text-decoration: none; text-shadow: none; width: 80px; min-height: 80px; background: url(https://artscolumbia.org/wp-content/plugins/intelly-related-posts/assets/images/simple-arrow.png)no-repeat; position: absolute; right: 0; top: 0; } .ub3c17e4c21f9daf294663e2be60ee707:hover .ctaButton { background-color: #34495E!important; } .ub3c17e4c21f9daf294663e2be60ee707 .centered-text { display: table; height: 80px; padding-left : 18px; top: 0; } .ub3c17e4c21f9daf294663e2be60ee707 .ub3c17e4c21f9daf294663e2be60ee707-content { display: table-cell; margin: 0; padding: 0; padding-right: 108px; position: relative; vertical-align: middle; width: 100%; } .ub3c17e4c21f9daf294663e2be60ee707:after { content: ""; display: block; clear: both; } READ: Hot and good Essay#include ;stdio.h;void hello(); /* This is a prototype notice the void. Void tells thecompiler that this functiondoes not return a value like return 0; */main() /* Main doesnt ever need to be prototyped */hello();return 0;}void hello(); /* Your prototype must look exactly like your real function */printf(Im in the function hello!);} Void is your return type. Other return types are int for returning integersuse float to return decimals and so on. /***********************************************************************************************/7th Ill introduce you to input. Ill teach you how to use gets() and scanf()and fgets() properlygets() takes a variable and place data into as do scanf() and fgets() In thenext example I will use all 3#include stdio.h#include conio.hmain()int x, y, z, ans;printf(What is X s value );gets(x);printf(What is Y s value );scanf(%d, y); /* Scanf is odd I dont recommend using it try and use getsand fgets more */ /* Whatever is used to print the variable type you are using is placed inparantheses and is used in front of whatever variable you are using */printf(What is Z s value);fgets(z, 25, stdin); /* fgets is kinda tricky at first glance */ /* first off you put what variable you want then how many integers orcharacterslong it can be and then stdin,stdin is a macro defined in stdio.h it is usedto represent standard input */ans=x+y+z;printf(Ans equals %d, ans);/************************************ ***********************************************************/8th Lets talk about decision statements like if and else. here is how if is usedif(VariableName==5) printf(Your variable is 5); }else is used after if, it is used like thisif(VariableName==5)printf(Your variable is 5);}elseprintf(I dont know what your variable is);}/***********************************************************************************************/9th Ill talk about While loops and do-while loops. Loops arent as hard asthey may seem. while loops are easy. Just watch and learn. #include stdio.hmain()int x=1;while(x2600)printf(X=%d,x);x++; /* adds 1 to x */}return 0;} /* While loops dont have to happen only if the right sequence happens dothey execute */Loops can be placed inside of IF and else statements if you want. That canbe very helpful if you want a process to happen a bunch if something happens Like the user pressingX instead of Y. Do-While loops are just as easy. They automatically execute at least once. #include stdio.hmain()int x=1;doprintf(X=%d,x);x++;}while(x2600);return 0;}The do tells the program to do this at least once and it doesnt see thewhile until it has already do the do. /***********************************************************************************************/10th Im going to tell you about another kind of loop the for loop. Forloops execute a given number of times and then stop. For loops are executed like this. for(x=1; x100; x++)printf(X=%d,x);}That prints 1 through 100. Thats about it about for loops there not veryhard. They can be prettyuseful. But I dont use them alot Im into While loops. /***********************************************************************************************/11th is all about Arrays. Arrays are consecutive places in memory. Arrayscan be integers and characters. They can be just about any size. Here is an example. #include stdio.hmain()int i2int i1 =2600int i2 =1982 /* Year I was born */printf( I1 = %d ,i1); printf( I2 = %d ,i2);return 0;}See how easy that was Arrays arent very hard at all. /***********************************************************************************************/12th Ill tell you about passing parameters to functions. Its nots to hardbut Ive said that about everything. First you must prototype it before main() I hope youremember how to prototype. Here is an example of passing parameters. #include stdio.hint next(int x);main()int age;printf(please enter you age );fgets(age, 3 ,stdin);age(age); /* Age is passed on to the next function */return 0;}next(int x);x++;printf(Next year you will be %d, x);return 0;}/***********************************************************************************************/13th Ill say a little sumthin about why C is good to Hacking. Its goodbecause it is so portable C can be used on all processors and Operating Systems. So if yourexploit you just wrote works onone UNIX like OS odds are it will work on another, therefore you dont haveto write a whole newprogram just to get a root shell. .u4c4218344e201a25c6d4e3ccb16b00a4 , .u4c4218344e201a25c6d4e3ccb16b00a4 .postImageUrl , .u4c4218344e201a25c6d4e3ccb16b00a4 .centered-text-area { min-height: 80px; position: relative; } .u4c4218344e201a25c6d4e3ccb16b00a4 , .u4c4218344e201a25c6d4e3ccb16b00a4:hover , .u4c4218344e201a25c6d4e3ccb16b00a4:visited , .u4c4218344e201a25c6d4e3ccb16b00a4:active { border:0!important; } .u4c4218344e201a25c6d4e3ccb16b00a4 .clearfix:after { content: ""; display: table; clear: both; } .u4c4218344e201a25c6d4e3ccb16b00a4 { display: block; transition: background-color 250ms; webkit-transition: background-color 250ms; width: 100%; opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; background-color: #95A5A6; } .u4c4218344e201a25c6d4e3ccb16b00a4:active , .u4c4218344e201a25c6d4e3ccb16b00a4:hover { opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; background-color: #2C3E50; } .u4c4218344e201a25c6d4e3ccb16b00a4 .centered-text-area { width: 100%; position: relative ; } .u4c4218344e201a25c6d4e3ccb16b00a4 .ctaText { border-bottom: 0 solid #fff; color: #2980B9; font-size: 16px; font-weight: bold; margin: 0; padding: 0; text-decoration: underline; } .u4c4218344e201a25c6d4e3ccb16b00a4 .postTitle { color: #FFFFFF; font-size: 16px; font-weight: 600; margin: 0; padding: 0; width: 100%; } .u4c4218344e201a25c6d4e3ccb16b00a4 .ctaButton { background-color: #7F8C8D!important; color: #2980B9; border: none; border-radius: 3px; box-shadow: none; font-size: 14px; font-weight: bold; line-height: 26px; moz-border-radius: 3px; text-align: center; text-decoration: none; text-shadow: none; width: 80px; min-height: 80px; background: url(https://artscolumbia.org/wp-content/plugins/intelly-related-posts/assets/images/simple-arrow.png)no-repeat; position: absolute; right: 0; top: 0; } .u4c4218344e201a25c6d4e3ccb16b00a4:hover .ctaButton { background-color: #34495E!important; } .u4c4218344e201a25c6d4e3ccb16b00a4 .centered-text { display: table; height: 80px; padding-left : 18px; top: 0; } .u4c4218344e201a25c6d4e3ccb16b00a4 .u4c4218344e201a25c6d4e3ccb16b00a4-content { display: table-cell; margin: 0; padding: 0; padding-right: 108px; position: relative; vertical-align: middle; width: 100%; } .u4c4218344e201a25c6d4e3ccb16b00a4:after { content: ""; display: block; clear: both; } READ: Discrimination in America Essay/***********************************************************************************************/Last but not least a sample program. #include stdio.hint blah(int x,int y);main()int a,b,r;printf(Enter some numbers );scanf(%d, a);scanf(%d, b);r=blah(a,b);printf(R = %d,r);return 0;}int blah(int x, int y)return x * y; }What does blah do and how does it work? You tell me. /***********************************************************************************************/Thats it for my little tutorial on C. I hope it helped you some. But forfurther info on C I suggest reading C programming in 12 easy lessons by Greg Perry from Sams Publishing. It helped me a shitload on learning C. You also might want to get some bookson C++ a subset of CYou can mail me at emailprotected
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.