C Program to Find Total of Even Integers

C Program to Reading Of Strings with Example

C Program for Reading of strings using %wc and %ws is explain in simple steps. The program illustrates the use of various field specifications for reading strings. When we use %wc for reading a string, the system will wait until the with character is keyed in.

Note that the specification %s terminates reading at the encounter of a blank space. Therefore, name2 has read only the first part of “Techno SAP” and the second part is automatically assigned to name3. However, during the second run, the string “Techno- SAP” is correctly assigned to name2.

C Program to Reading Of Strings with Example

main()
{
int no;
char name1[15], name2[15], name3[15];
printf("Enter serial number and name one\n");
scanf("%d %15c", &no, name1);
printf("%d %15s\n\n", no, name1);
printf("Enter serial number and name two\n");
scanf("%d %s", &no, name2);
printf("%d %15s\n\n", no, name2);
printf("Enter serial number and name three\n");
scanf("%d %15s", &no, name3);
printf("%d %15s\n\n", no, name3);
}

Output Display,

Enter serial number and name one
1 123456789012345
1 123456789012345r
Enter serial number and name two
2 Techno SAP
2 Techno
Enter serial number and name three
2 SAP
Enter serial number and name one
1 123456789012
1 123456789012 r
Enter serial number and name two
2 Techno-SAP
2 Techno-SAP
Enter serial number and name three
3 London
3 London

Let me know if you find any difficulty in understanding this C Program with example and I would be glad to explain it further.