Page 15 - PROGRAMMING IN C_Neat
P. 15
for( j=0; j<2; j++)
{
printf(“%d”, a[i][j]);
}
}
_______________________________________________________________________________________
9. Explain the functions used to read and write strings. *
Reading Strings:
scanf():
%s conversion character should be used in scanf() function to read a string.
General Form:
scanf(“%s”, variablename);
Example:
char a[10];
scanf(“%s”, a);
gets():
Used to read a string from the keyboard.
General Form:
gets(variablename);
Example:
char a[10];
gets(a);
Writing Strings:
printf():
%s conversion character should be used in printf() function to write a string.
General Form:
printf(“%s”, variablename);
Example:
char a[10];
scanf(“%s”, a);
printf(“%s”, a);
puts():
Used to display a string on the monitor.
General Form:
Example: puts(variablename);
puts(“Kandan”);
_______________________________________________________________________________________