So:
char *someCArray; # something
I want to print out "ethin" from "something".
You can access an array element using an expression which contains the name of the array followed by the index of the required element in square brackets. To print it simply pass this method to the println() method.
yes, %c will print a single char: printf("%c", 'h'); also, putchar / putc will work too.
The abbreviation char is used as a reserved keyword in some programming languages, such as C, C++, C#, and Java. It is short for character, which is a data type that holds one character (letter, number, etc.) of data. For example, the value of a char variable could be any one-character value, such as 'A', '4', or '#'.
You can use the printf
precision specifier
#include <stdio.h>
int main(void) {
char s[] = "something";
int start = 3;
int len = 5;
printf("%.*s\n", len, s + start);
return 0;
}
Code also posted to codepad: http://codepad.org/q5rS81ox
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With