Sunday, March 28, 2010

gets vs scanf for reading string

gets(): Reads characters from stdin and stores them as a string into str until a newline character ('\n') or the End-of-File is reached.


scanf(): This function ignores whitespace character, newline, tab characters encountered before the next non-whitespace character.

strlen() does not include the \0 character.

Monday, September 21, 2009

To take inputs from console - java

import java.util.Scanner;

class test {
public static void main (String [] args) {
Scanner in = new Scanner(System.in);

System.out.println("Input string is " + in.nextLine());
System.out.println("Input number is " + in.nextInt());

in.close();
}
}

Thursday, September 17, 2009

Setting environment variables in windows:
Open the Control Panel (Start ‣ Control Panel), start the System program. Click the Advanced tab and select the Environment Variables button. You can edit or add to the User Variables.

Sunday, September 13, 2009

ASCII character list : http://web.cs.mun.ca/~michael/c/ascii-table.html

Tips

* fgetc gets one character by character. So if you have 12 followed by newline written in a file, fgets will return 1 in the first call, 2 in the second call and 10 (for newline) in third call.

*fgets reads characters until it encounters a newline character. newline is considered as a valid character and therefore it is included in the string copied.