Stack1's Posts
Nairaland Forum › Stack1's Profile › Stack1's Posts
1 2 3 4 5 6 7 8 9 10 11 (of 12 pages)
DabFrankNG:might not had been the guys fault for stopping the tutorials really, atimes time itself and situation's doesn't permit, but i'll try |
[size=14pt]Formatted Input/Output[/size] Now we'll learn a bit about the printf and scanf input/output functions We have been previously using the getchar and putchar functions for character input and output, while this functions work well for single character input and output many programs usually require much more complex and detailed way to get program input and output values |
PRINT HISTOGRAM OF THE LENGTH OF EACH WORD. This next program extends the last one, we detect wen we are in a word and print a horizontal Histogram representing the length of each word //print histogram of length of each word
If you tried out the last example you'll notice the similarities, the major difference is that when we are in a word we print a horizontal bar | for each character thereby printing an Histogram for each word... more explanation in a bit, however do try it out and make sure it works |
This program count the characters, lines, and words in an input
The code is pretty self explanatory as it has been heavily commented so try to study it A new construct #define seen in the code is a pre-processor directive (similar to #include) #define is used to introduce constants (values not expected to change) into the program. As an example if you where writing a program calculating radius instead of creating an integer variable for PI like int PI = 3.142 its more appropriate to do #define PI 3.142..., so anywhere you use PI, the value 3.142 would be substituted |
This next program remove's extra spaces between text, so to try it enter any amount of text with lot's of space between the text's and the program would detect and truncate such space(s) to just one space
Now lets go through it. Note that we start by declaring two integer variables in the main function c and last_char_is_blank, we would use the last_char_is_blank variable, as a control variable to detect multiple spaces, We read input characters into the variable c in the while loop Next we have the if statement if(c==32) The number 32 is the ASCII value for SPACE and we could have equally done if(c== ' ') , and achieved the same result, if the character entered is a space, the if block is executed this shows that you can use any ASCII decimal value instead of an Actual character. The next line if(last_char_is_blank == 0) checks to see if the control variable has not been set the variable last_char_is_blank is initially assigned a value of zero so this test would pass and the following statements putchar(c); would be executed, the first statement outputs the space character ( remember we're still inside the if statement that detected a space) then the next statement sets our control variable last_char_is_blank to one On the next run of the loop if the imputed character is again a space, the if statement detects it, and so when the check if(last_char_is_blank == 0) is executed, the test fails since last_char_is_blank would now set to 1 (provided the previous character was a space) If the imputed character is however not a SPACE character, the first if statement fails and the else block is executed, so the non-space character gets printed. and the last_char_is_blank variable is reset to ZERO This way multiple spaces within the text is prevented. Enter the code and run-it to fully understand |
dhtml18:toh, taught as much, hope it doesn't occur frequently, don't know how much more of such frustrations i can take, but by the way sef i usually put program text between d code tag.., it is well sha |
nawa o, i was trying to post afew more tutorials yesterday when i got banned by the antispam bot for a full 24hrs, biko antispam bot wetin i do u |
Lets look at some more Loop/Control structures examples The program below simply counts the number of lines in an input
Here's how the program works 1. In the main function we declare two int variables c and nl 2.In the while loop we read in characters into variable c until we detect the END_OF_FILE character 3. now in the body of the while loop we check for the newline character \n and whenever it is detected it means the user entered text on a new line so we increment the nl variable ( variable nl here is our number-of-lines counter) When entering input for this program enter as many number of lines of text as you wish then press Crtl+Z, this would send the EOF character to your program and the loop would exit The next line containing the function printf, prints out the value of the[b] nl[/b] variable, which shows the number of lines in our input |
If you typed in the codes correctly both pages should now link to each other. So lets look at the anatomy of the Anchor tag The Anchor tag represented by <a> is a non-empty (i.e it has an opening and closing tag) tag as well as an inline-tag (i.e. it displays inline and so doesn't cause a line-break) The link we put in page2.html was written as <a href="index.html" Link to the index page">Go back to the index page</a> So first we started with the opening <a> tag, you'll notice the tag has some attributes, the most important attribute in an anchor tag is called the href The href attribute is what we use to specify the resource we are linking to, if its another web-page as in our example we simply put the name and extension of the page, though if the page was in another folder we would also append the folder's name, the value we put in the href attribute is called URL - Uniform Resource Locator. URL's could be relative or absolute the one, if the URL contains the full-path of what we're linking to, it's called an absolute URL, else if it doesn't contain the full path it is a relative URL. see this Wikipedia page for more info on URL's https://en.wikipedia.org/wiki/Uniform_Resource_Locator The <a> element can play several roles, depending on which attributes are set. The most common attribute you'll use is the href attribute, which defines what resource the link points to. This attribute can contain different values: A URL relative to the current folder, e.g., "../../help/help.html" (two dots means "go up one level in the site folder hierarchy" ), or a URL absolute to the server root, e.g., "/help/help.html" (a forward slash at the beginning of the URL means the address starts at the root of the folder hierarchy the current page is on). A URL on a different server, for example "ftp://ftp.gnu.org/" or " https://developer.mozilla.org ". A fragment identifier or id preceded by a hash sign, e.g., "#menu". This points to a target inside the current document rather than an external URL. |
we'll continue to use the folder structure created earlier, so if you do not have that in-place now would be a good time time to create it Ok so open a new notepad document and save it as page2.html in the same directory as our index file. Then add the following code to page2
next open the index.html page for editing add a link under the div tag so the code should look like this
save both pages and open the index.html file in your browser, you should now have a link element that enables you navigate to the page2.html, and another link on page2.html that takes you back to the index page |
[size=14pt]Linking with the <a> -Anchor Tag[/size] Links are parts of an HTML document that point or link to other resources — other HTML documents, text files, PDF files, etc. Some links are followed automatically by the browser, like the <link> elements we used to add external CSS files to the document earlier. But generally, when we talk about links we mean those that are created by the page author and are meant to be activated (or clicked) by the user. These Elements are called anchors, and you add them to the HTML document using the <a> element/tag. |
romme2u:kk thanks, by or before sunday i'll include some demo samples |
why is stuff posting twice?? ![]() |
romme2u:its a standalone library no dependencies,tho i included code from an external JavaScript encryption library project for the crypt and hash modules, but no deependencies whatsoever just drop it in and go. for speecific areas the demo site would be up soon, so that'll be taken care of, but yeah it handles dom manipulations, animations, language utilities, advanced string methods like sprintf, quite advanced XHR/Socket stuff like sending multiple request on a single socket conection etc. but lemme work on d demo site first, though i believe developers should be able to work even with jusy d API docs which is available |
romme2u:its a standalone library no dependencies,tho i included code from an external JavaScript encryption library project for the crypt and hash modules, but no deependencies whatsoever just drop it in and go. for speecific areas the demo site would be up soon, so that'll be taken care of, but yeah it handles dom manipulations, animations, language utilities, advanced string methods like sprintf, quite advanced XHR/Socket stuff like sending multiple request on a single socket conection etc. but lemme work on d demo site first, though i believe developers should be able to work even with jusy d API docs which is availablw |
KazukiIto:oh actually i have, already used it in 2 live project for a client, and was the only client side library i used.. by d way its bn in development for upto two years now so yeah already had maximum fun already working on d demos site so u guuys can have fun with it too, tho that would take sometime |
KazukiIto:oh actually i have, already used it in a live project for a client, and was the only client side library i used.. |
Kodejuice:yeah i know, oops right. i currently have only an API documentation out would start working on demo samples soon, its all just very time consuming u know |
Just committed my JavaScript project to GitHub, its a pretty advanced general purpose library, i started the project about two years back and have being hosting it on Sourceforge, but decided to move it to GitHub today, it has full HTML documentation for its API, so if you want to check it out you could start from there... hoping for some feedback on this. project url : https://github.com/solutionstack/tigerjs/ PS. Its a pretty comprehensive and complex project so if you have problems setting it up just let me know |
The ternary operator ( ?: ) is another powerful and useful conditional expression used in C and C++. It's effects are similar to the if statement but with some major advantages. The basic syntax of using the ternary operator is thus: (condition) ? (if_true ) : (if_false ) which is basically the same as
Therefore if "condition" is true, the second expression is executed ("if_true" ), if not, the third is executed ("if_false" ). as an example, assuming we have two int variables, and we wanted to compare them
This could be re-written as
A notable difference here is that the result of a Tenary expression can be stored or assigned to a variable, while an if-else statement doesn't return a result, though the assignment can be done within its execution block/scope |
The C language includes a wide variety of powerful and flexible control statements, we have already seen the "loop-control" statements, now we look at the decision making statements. The most useful of these are described in the following. The if-else statement is used to carry out a logical test and then take one of two possible actions, depending on whether the outcome of the test is true or false. The else portion of the statement is optional. Thus, the simplest possible if-else statement takes the form:: if (expression) statement The expression must be placed in parenthesis, as shown. In this form, the statement will only be executed if the expression has a nonzero value i.e if expression if true, If the expression has a value of zero / if expression is false) then the statement will be ignored. The statement can be either simple or compound.
An else statement matches the nearest previous if statement in the same scope or block: The else in this code:
|
shobam1410:while i must agree this is really a nice collection of books (i actually have a few of them) this thread isn't for advertisements, if you are going to post please post on relevant topics being discussed, thank you |
bestiyke:i have some books, but low on data to upload fir now, this page is however very sufficient http://www.w3schools.com/cssref/ or this https://developer.mozilla.org/en-US/docs/Web/CSS/Reference |
thanks @romme2u, no p, looking forward to tangle |
its obvious no one is following, not even 1 question no, twas meant to b interactive, even for those who don sabi, you could add your own post's for current topics |
Olumyco:wouuld definitely do that, thanks |
Olumyco:the Fx module allows you apply lots of animation and transition effect to an element via script, see the conntained documentation for examples, small memory footprint means it doesn't signigicantly increase the memory usage of the page its running on, i actually did bemchmarks and compared with sench and dojo libraries... |
and also make una ask questions oo.. |
very tired tonight so i'll just run down a few C operators and their usage, most would be understood from their mathematical usage anyway, then gain forgive me I'm so stressed up right now, lemme leave you with this page that rounds up the C operators pretty well http://www.tutorialspoint.com/cprogramming/c_operators.htm Their usage would still be explained further in examples to come.. ..Serious sleep-mode things ![]() |
We are now going to create another web-page login.html in the server sub-folder, and look at how we can link to it from the index page |
Now that we have successfully linked the external style sheet with the index.html file, lets style the web-page a bit more open the index.css file for editing and add the following
what we have done here is to use the id attributes of elements in the page to style them. First we add a color style to the SPAN element with id header-text, thereby changing its color (note the selector #header-text) We then change the font-size of the same SPAN element Next we add a text-align CSS declaration to the div element, the DIV element contains a span element, so by setting tthe text-align of the DIV element to center, we automatically centralize any text element(s) it contains. Save and refresh your browser, make sure the web-page text is now centralized and bigger |

