how to print the first character of a string in c 1

how to print the first character of a string in c

#include  
#include 
 
int main(void)  
{ 
	char c[100]; 
	scanf("%s",c); 
	/*strlen(c) gives total length of string . string index starts from 0 
	last index of character is strlen(c)-1*/ 
	int l = strlen(c)-1; 
	printf("%c %c",c[0],c[l]); 
	return 0; 
} 

Here is what the above code is Doing:
1. It takes a string as input.
2. It finds the length of the string using strlen() function.
3. It prints the first and last character of the string.

Input:
geeksforgeeks

Output:
g s

Similar Posts