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.
Sunday, March 28, 2010
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();
}
}
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
Sunday, September 13, 2009
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.
*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.
Subscribe to:
Posts (Atom)